菜鸟的博客

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

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

2023.5.14

复制代码
 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 }
复制代码

 

posted on   hhmzd233  阅读(10)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示