复制元素copy

#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
#include <functional>

using namespace std;

int main()
{
	list<int> ilist;

	for (int i = 0; i <= 9; ++i)
		ilist.push_back(i);

	vector<int> ivec(ilist.size() * 2);
	for (vector<int>::iterator iter = ivec.begin(); iter != ivec.end(); ++iter)
		cout << *iter << ' ';
	cout << endl;

	for (list<int>::iterator iter = ilist.begin(); iter != ilist.end(); ++iter)
		cout << *iter << ' ';
	cout << endl;

	copy(ilist.begin(), ilist.end(), ivec.begin());
	for (vector<int>::iterator iter = ivec.begin(); iter != ivec.end(); ++iter)
		cout << *iter << ' ';
	cout << endl;  // 输出的是0123456789000000000

	copy_backward(ilist.begin(), ilist.end(), ivec.end());  //copy_backward是从后面开始copy,
	for (vector<int>::iterator iter = ivec.begin(); iter != ivec.end(); ++iter)
		cout << *iter << ' ';
	cout << endl;  // 输出是01234567890123456789,


	return 0;
}

你可能感兴趣的:(复制元素copy)