I em having trouble with a list iteration.
I have to tranverse a list rather frequently, if an element is flagged for deletion then it must be removed.
for (list<int> iter = l.begin(); iter != l.end(); ++iter)
{
iter = l.erase(iter);
cout << (*iter) << endl;
}
This deletes every even number... since the first element is deleted, the 2nd is returns, then it is incremented by the for loop and deleted.




Reply With Quote