拷贝算法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