2013-01-10 67 views
12

尝试对整数数组进行排序,并在搜索一些Google之后,遇到了使用std::sort的解决方案,并伴随此错误:namespace "std" has no member "sort"名称空间“std”没有会员“排序”

只是为了disqalify,我不是使用std命名空间的任何疑虑,这里是我的头:

#include "stdafx.h" 
#include <iostream> 
#include <fstream> 
#include <sstream> 
#include <string> 
using namespace std; 
+3

你不应该在标题中使用'namespace';不是每个包含头文件的人都需要全局命名空间受到污染。 –

+1

更糟糕的是,全局名称空间受到不同事物的污染,具体取决于过去和将来包含的顺序头文件。 – Yakk

回答

31

地址:

#include <algorithm> 

std::sort()参考页说明。

请参阅Using std Namespace,Why is "using namespace std" considered bad practice?和其他许多关于SO讨论using namespace std;的问题。

+0

这解决了我的错误_namespace“std”在尝试使用Android NDK上的gnustl_static进行编译时没有成员“sort”_。对std :: sort的引用在XCode和Visual Studio中起作用,但对于NDK,我需要从此答案中添加包含。谢谢! –

相关问题