#include <iostream>
#include <vector>
using namespace std;
void printvector (vector<int>& v)
{
for (vector<int>::iterator it = v.begin(); it != v.end(); it ++)
{
cout << *it << " ";
}
cout << endl;
}
void test01 ()
{
vector<int> v1;
for (int i = 0; i < 10; i ++)
{
v1.push_back(i);
}
printvector(v1);
if (v1.empty())
{
cout << "v1 is empty" << endl;
}
else
{
cout << "v1 is not empty" << endl;
cout << "v1's capacity is " << v1.capacity() << endl;
cout << "v1's size is " << v1.size() << endl;
}
//重新指定大小
v1.resize(16, 100); //利用重载的版本,可以指定默认填充值,参数2
printvector(v1); //如果重新指定的比原来长,默认用0填充
v1.resize(5);
printvector(v1); //超出部分被截取
}
int main ()
{
test01();
return 0;
}