vector的erase 用法

// erasing from vector
#include <iostream>
#include <vector>
using namespace std;

int main ()
{
unsigned int i;
vector<unsigned int> myvector;

// set some values (from 1 to 10)
for (i=1; i<=10; i++) myvector.push_back(i);

// erase the 6th element
myvector.erase (myvector.begin()+5);

// erase the first 3 elements:
myvector.erase (myvector.begin(),myvector.begin()+3);

cout << "myvector contains:";
for (i=0; i<myvector.size(); i++)
cout << " " << myvector[i];
cout << endl;

return 0;
}

posted on 2012-02-21 13:43  chateldon  阅读(653)  评论(0编辑  收藏  举报

导航