3/09/2008

vector erase

Vector in stl allow me to erase element.
This way is calling "erase" method.

Following codes are sample.


#include < iostream >
#include < vector >
using namespace std;

int main(void)
{
vector< int > tmp;

tmp.push_back(1);
tmp.push_back(2);
tmp.push_back(3);
tmp.push_back(4);

for( int i = 0;i < tmp.size(); i++){
cout << tmp[i] << endl;
}

cout << "erase" << endl;
vector< int >::iterator ite = tmp.begin();
ite++;
ite++;
tmp.erase(ite);
for( int i = 0;i < tmp.size(); i++){
cout << tmp[i] << endl;
}
return 0;
}

No comments: