试图对整数数组进行排序,经过一些搜索,找到了使用 std::sort
的解决方案,但是遇到了这个错误:命名空间 "std" 没有成员 "sort"
。
为了排除我没有使用 std 命名空间的疑虑,这是我的头文件:
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
添加:
#include <algorithm>
根据std::sort()
参考页面所述。
请查看使用std命名空间、为何“using namespace std”被认为是不好的实践?及其他讨论using namespace std;
的SO问题。
using namespace
,因为并非每个包含该头文件的人都希望全局命名空间被污染。 - Mike Seymour#include "stdafx.h"
。尽管这是一个非常古老的问题,但我评论的目的是帮助未来读者解决像我一样在6年后看到这个问题的困扰。 - drescherjm