我不知道这是一个有趣的问题还是什么,但是当我尝试运行这段代码,我得到了一些错误。你认为老师忘了放入#include行吗?以下代码产生了什么?
#include <iostream>
#include <vector>
using namespace std;
int display(int val) {
cout << val << ",";
}
int main() {
int a[] = {1, -4, 5, -100, 15, 0, 5};
vector<int> v(a, a + 7);
sort(v.begin(), v.end(), greater<int>());
for_each(v.begin(), v.end(), display);
}
。
g++ -ggdb -c test.cpp
test.cpp: In function 'int main()':
test.cpp:13:41: error: 'sort' was not declared in this scope
test.cpp:14:38: error: 'for_each' was not declared in this scope
make: *** [test.o] Error 1
感谢
在当你未来的错误,如这些,你可以搜索一个C++的参考,像我一样的[排序()](http://en.cppreference.com/w/cpp/algorithm/sort),通常你“会在这头是在 – ChiefTwoPencils 2013-02-18 23:25:25