2013-01-10 25 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,我需要從此答案中添加包含。謝謝! –

相關問題