菜鸟的博客

纵有疾风起,人生不言弃。

导航

2023.5.13

 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 }
25 
26 int main()
27 {
28     test01();
29     return 0;
30 }

 

posted on 2023-05-14 17:07  hhmzd233  阅读(12)  评论(0)    收藏  举报