vertor容器裏面的insert()方面要求插入的位置,是元素的迭代器位置,而不是元素的下標

#include
#include <vector>


using namespace std;


int main()
{
vector<int> v(5);


v[0]=0;
v[1]=2;
v[2]=4;

vector<int>::iterator index;
for(index = v.begin(); index != v.end(); ++index)
{
cout << *index << ' ';
}
cin.get();

v.insert(v.begin(),1);
v.insert(v.begin()+1,100);

for(index = v.begin(); index != v.end(); ++index)
{
cout << *index << ' ';
}
cin.get();

return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章