我尝试使用C++ boost 库中的for_each。这是我拥有的代码。
#include <iostream>
#include <vector>
#include <boost/fusion/algorithm/iteration/for_each.hpp>
#include <boost/fusion/include/for_each.hpp>
using namespace std;
int main() {
vector<int> vec;
vec.push_back(1);
vec.push_back(2);
vec.push_back(3);
boost::for_each(
vec,
[](int val){
cout << val << "\n";
}
);
return 0;
}
这就是我编译代码的方式:
g++ -std=c++0x -I /opt/software/boost/1.50_ubuntu12.4lts_gcc4.7.2/include -c try_boost.cpp
g++ -o try_boost -L/opt/software/boost/1.50_ubuntu12.4lts_gcc4.7.2/lib try_boost.o -lboost
结果我得到:
error: ‘for_each’ is not a member of ‘boost’
有谁知道为什么它不起作用?