#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
void test01()
{
vector<int>v1;
//预留空间
v1.reserve(10000);
int num = 0;
int* p = NULL;
for (int i = 0; i < 10000; i++)
{
v1.push_back(i);
if (p != &v1[0])
{
p = &v1[0];
num++;
}
}
cout << "num = " << num << endl;
}
int main()
{
test01();
system("pause");
return 0;
}
07_vector容器_预留空间
最新推荐文章于 2024-01-11 21:28:52 发布