push_back的使用

 push_back   是算法语言里面的一个  函数名。     C++ 中的vector头文件里面就有这个push_back函数,在vector类中作用为在vector尾部加入一个数据。string中也有这个函数,作用是字符串之后插入一个字符。

push_back的使用

 1 #include <iostream>
 2 #include <vector>
 3 #include <string>
 4 
 5 using namespace std;
 6 
 7 int main()
 8 
 9 {
10     vector<int> v1;
11     v1.push_back(10);
12     v1.push_back(11);
13     v1.push_back(12);
14 
15     vector<int> v2(v1);
16 
17     vector<int> v4(10, 8);
18     vector<int> v6(8);//输出的是8个0,
19 
20     vector<string> v5(8, "xiao cui");
21     vector<string> v7(9); //输出的是9个空串
22 
23     for (vector<int>::size_type i = 0; i != v5.size(); ++i)
24         cout << v5[i] << endl;
25 
26     cout << v1[0] << endl;
27     cout << v2[0] << endl;
28     cout << v4[0] << endl;
29     cout << v5[0] << endl;
30     cout << v6[0] << endl;
31     cout << v7[0] << endl;
32 
33     v1[0] = 100;
34     cout << v1[0] << endl;
35 
36 
37     return 0;
38 }

View Code

push_back的使用

https://blog.csdn.net/qq_31248551/article/details/50499702

https://blog.csdn.net/Appleeatingboy/article/details/79195289

原文链接: https://www.cnblogs.com/thebreakofdawn/p/9501873.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    push_back的使用

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/279689

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月15日 上午4:21
下一篇 2023年2月15日 上午4:22

相关推荐