stl(二)------如何在vector中添加元素,以及遍历元素
#include “stdafx.h”
#include
#include
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
vector
int i;
for ( i= 0; i < 6; i++)
{
Index.push_back(i); //元素添加
}
//第一种用遍历器输出verctor中的元素
vector
for (iter = Index.begin(); iter!=Index.end(); ++iter)
{
cout<<*iter<<endl;
}
//第二种输出方式可以以数组方式输出
for (i = 0; i < Index.size(); i++)
{
cout<<Index[i]<<endl;
}
return 0;
}
还没有评论,来说两句吧...