1 #include <iostream>
2 #include <algorithm>
3 #include <vector>
4 #include <list>
5 using namespace std;
6
7 void main()
8 {
9 vector<
int> myint{
1,
2,
3,
4,
5 };
10 list<
int> mylist{
10,
9,
7,
6,
5 };
11 //copy不能自动拓展,需要被拷贝的有足够的空间
12 copy(myint.begin(), myint.end(), mylist.begin());
13 for_each(mylist.begin(), mylist.end(), [](
int x) {cout << x <<
endl; });
14 //反向拷贝
15 /*copy_backward(myint.begin(), myint.end(), mylist.end());
16 for_each(mylist.begin(), mylist.end(), [](int x) {cout << x << endl; });*/
17
18 //交换两个容器
19 vector<
int> myint1{
1,
2,
3,
4,
5 };
20 vector<
int> myint2{
6,
7,
8,
9,
10 };
21 swap(myint1, myint2);
22 cin.
get();
23 }
转载于:https://www.cnblogs.com/xiaochi/p/8645574.html