本文共 1345 字,大约阅读时间需要 4 分钟。
#include#include #include #include using namespace std; class GenByTwo { public: GenByTwo (int _seed = 0):seed(_seed){} int operator() () {return seed += 2;} private: int seed; }; void operate(int &rhs) { cout << rhs << " "; rhs += 1; } int main(int argc, char* argv[]) { vector v(10); generate(v.begin(), v.end(), GenByTwo(2)); for_each(v.begin(), v.end(), operate); std::cout << std::endl; //print copy(v.begin(), v.end(), ostream_iterator (cout, " ")); return 0; }
4 6 8 10 12 14 16 18 20 22
5 7 9 11 13 15 17 19 21 23
#includetime: 66 ms// std::cin, std::cout#include // std::istream_iterator#include #include
转载地址:http://balnb.baihongyu.com/