H
happyvalley
Hi,
I want to remove some elements from a vector, the following code
doesn't work, seems it doesn't allow me to remove an element when
iterating the vector. (make sense), just wonder, how to do this?
thank
vector<int> IntVec;
vector<int>::iterator intIterator;
for(int i=0; i<10;i++) IntVec.push_back(i);
for(int i=0; i<10;i++) IntVec.push_back(i);
for(int i=0; i<10;i++) IntVec.push_back(i);
for(intIterator = IntVec.begin(); intIterator !=IntVec.end();
intIterator++)
{
if(*intIterator == 2)
IntVec.erase(intIterator);
}
I want to remove some elements from a vector, the following code
doesn't work, seems it doesn't allow me to remove an element when
iterating the vector. (make sense), just wonder, how to do this?
thank
vector<int> IntVec;
vector<int>::iterator intIterator;
for(int i=0; i<10;i++) IntVec.push_back(i);
for(int i=0; i<10;i++) IntVec.push_back(i);
for(int i=0; i<10;i++) IntVec.push_back(i);
for(intIterator = IntVec.begin(); intIterator !=IntVec.end();
intIterator++)
{
if(*intIterator == 2)
IntVec.erase(intIterator);
}