#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> a(30, 2);//容器容量大小为30,初始值为2
cout << a.capacity() << " " << a.size() << endl;
a.push_back(9);//想容器中后加如一个数,容器扩容,容量变为60, 也就是再扩一个已经定义的30的大小
cout << a.capacity() << " " << a.size() << endl;
return 0;
}
欢迎使用优快云-markdown编辑器
最新推荐文章于 2021-01-07 23:01:28 发布