C++ STL copy copy_backward
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <list>
using namespace std;
int main()
{
list<int> list1;
for (int k=0;k<10;k++)
{
list1.insert(list1.end(),k);
}
list<int>::iterator list_iter1;
for (list_iter1 = list1.begin();list_iter1 != list1.end();++list_iter1)
{
cout << *list_iter1 << " ";
}
cout << endl;
cout << "----------------------------------------------------------" << endl;
vector<int> vec1(list1.size()*2);
vector<int>::iterator vec_iter1;
for (vec_iter1 = vec1.begin();vec_iter1 != vec1.end(); ++vec_iter1)
{
cout << *vec_iter1 << " ";
}
cout << endl;
cout << "----------------------------------------------------------" << endl;
copy(list1.begin(),list1.end(),vec1.begin());
for (vec_iter1 = vec1.begin(); vec_iter1 != vec1.end(); ++vec_iter1)
{
cout << *vec_iter1 << " ";
}
cout << endl;
cout << "----------------------------------------------------------" << endl;
copy_backward(list1.begin(),list1.end(),vec1.end());
for (vec_iter1 = vec1.begin(); vec_iter1 != vec1.end(); ++vec_iter1)
{
cout << *vec_iter1 << " ";
}
cout << endl;
cout << "----------------------------------------------------------" << endl;
system("pause");
return 0;
}
========================================================
0 1 2 3 4 5 6 7 8 9
----------------------------------------------------------
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
----------------------------------------------------------
0 1 2 3 4 5 6 7 8 9 0 0 0 0 0 0 0 0 0 0
----------------------------------------------------------
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
----------------------------------------------------------
请按任意键继续. . .