Recently wrote a few questions, using the STL set this container, when I want to traverse the set to complete a specific erase operation, but there is Map/set iterator not incrementable exception report.
That's what most people write:
Set<int> S;
for (Set<int>::iterator it = S.begin (); It! = S.end (); it++)
if (a condition) erase (IT);
The exception report with
Map/set iterator not incrementable was discovered after running, because this element in the collection s does not exist after performing the erase (it) operation, so it The point of course is not still the original address.
So this time we want to make it point to the last element of the deleted element, you can do this:
Set<int> S;
for (Set<int>::iterator it = S.begin (); It! = S.end ();)
if (a condition) it = erase (it); C++11 Erase returns a iterator and points to the next element of the deleted element
else it++; Because erase is not used, you can still it++
I hope we can solve the problem.