#include <iostream>
#include<vector>
using namespace std;
int main()
{
vector<int> vec;
int i;
//显示vec的原始大小
cout<<"vector size="<<vec.size()<<endl;
//推入5个值到向量中
for(i=0;i<5;i++)
{
vec.push_back(i);
}
//显示vec扩展后的大小
cout<<"extended vector size="<<vec.size()<<endl;
//访问向量中的5个值
for(i=0;i<5;i++)
{
cout<<"value of vec["<<i<<"]="<<vec[i]<<endl;
}
//使用迭代器iterator 访问值
vector<int>::iterator v=vec.begin();
while(v!=vec.end())
{
cout<<"value of v="<<*v<<endl;
v++;
}
return 0;
}
//debug
//vector size=0
//extended vector size=5
//value of vec[0]=0
//value of vec[1]=1
//value of vec[2]=2
//value of vec[3]=3
//value of vec[4]=4
//value of v=0
//value of v=1
//value of v=2
//value of v=3
//value of v=4