C++ 命名空间“std”没有成员“sort”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14259993/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
namespace "std" has no member "sort"
提问by Binny Zupnick
Trying to sort an array of Integers and after some googling, came across the solution using std::sort
accompanied by this error: namespace "std" has no member "sort"
.
尝试对整数数组进行排序,经过一些谷歌搜索后,遇到了使用std::sort
伴随此错误的解决方案:namespace "std" has no member "sort"
。
Just to disqalify any qualms that I'm not using the std namespace, here is my header:
只是为了消除我没有使用 std 命名空间的任何疑虑,这是我的标题:
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
回答by hmjd
Add:
添加:
#include <algorithm>
as stated in the std::sort()
reference page.
如std::sort()
参考页所述。
See Using std Namespace, Why is "using namespace std" considered bad practice?and many other questions on SO discussing using namespace std;
.
请参阅使用 std 命名空间,为什么“使用命名空间 std”被认为是不好的做法?以及关于 SO 讨论的许多其他问题using namespace std;
。