Mega Code Archive

 
Categories / C++ Tutorial / Vector
 

Mutating Sequence Algorithm

#include <iostream> #include <vector> #include <algorithm> using namespace std; template<class T> class Print { public:      void operator()(const T& t)      {          cout << t << " ";      } };   int main() {      Print<int>    DoPrint;      vector<int>    vInt(10);        fill(vInt.begin(), vInt.begin() + 5, 1);      fill(vInt.begin() + 5, vInt.end(), 2);        for_each(vInt.begin(), vInt.end(), DoPrint);        return 0; }