拷贝算法copy

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class Print
{
public:
   void operator()(int i)
   {
      cout << i << endl;
   }
};

int main()
{
   vector<int> v;
   for(int i = 0; i < 5; i++)
   {
      v.push_back(i);
   }

   vector<int> vTarget;
   vTarget.resize(v.size());

   copy(v.begin(), v.end(), vTarget.begin());
   for_each(vTarget.begin(), vTarget.end(), Print());
   
   return 0;
}
$ ./a.out 
0
1
2
3
4
posted @ 2022-07-31 16:13  thomas_blog  阅读(17)  评论(0编辑  收藏  举报