#include<iostream>
#include<vector>
using namespace std;
//vector容器预留空间
void printVector(vector<int>&v)
{
for (vector<int>::iterator it; it != v.end(); it++)
{
cout << *it << " ";
}
cout << endl;
}
void test01()
{
//利用reserve预留空间
vector<int>v;
v.reserve(100000);
int num = 0;//统计开辟数据
int *p = NULL;
for (int i = 0; i < 100000; i++)
{
v.push_back(i);
if (p != &v[0])
{
p = &v[0];
num++;
}
}
cout << "num = " << num << endl;
}
int main()
{
test01();
system("pause");
return 0;
}