我不知道这是一个技巧问题还是什么,但是当我尝试运行这段代码时,我得到了一些错误。您认为老师忘记添加#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
谢谢