1 #include <iostream>
2 using namespace std;
3 #include <vector>
4 void printVector(vector<int>&v)
5 {
6 for (vector<int>::iterator it = v.begin(); it < v.end(); it++)
7 {
8 cout << *it << " ";
9 }
10 cout << endl;
11 }
12 void test01()
13 {
14 vector<int> v1;//默认构造,无参构造
15 for (int i = 0; i < 10; i++)
16 {
17 v1.push_back(i);
18 }
19 printVector(v1);
20 vector<int>v2(v1.begin(), v1.end());//通过区间方式进行构造
21 printVector(v2);
22 vector<int>v3(10, 100);//通过n个element的方式进行构造
23 printVector(v3);
24 if (v1.empty())
25 {
26 cout << "v1为空" << endl;
27 }
28 else
29 {
30 cout << "v1不为空" << endl;
31 }
32 cout << "v1的容量:" << v1.capacity() << endl;
33 cout << "v1的大小:" << v1.size() << endl;
34 v1.resize(20, 100);
35 printVector(v1);
36 }
37
38 int main()
39 {
40 test01();
41 return 0;
42 }