C++ for each on vector
#include <iostream> #include <algorithm> #include <vector> using namespace std; void ProcessVector(vector<int>& vect) { vector<bool> Result; Result.resize(vect.size()); /*ww w. jav a 2s . c om*/ transform(vect.begin(), vect.end(), Result.begin(), [](int x){return x > 3;}); cout.setf(ios::boolalpha); for_each(Result.begin(), Result.end(), [](bool x){cout << x << endl;}); } int main() { vector<int> myV; myV.push_back(1); myV.push_back(2); myV.push_back(3); myV.push_back(4); ProcessVector(myV); }