How to iterate over a STL set and selectively remove elements?

Posted by zr on Stack Overflow See other posts from Stack Overflow or by zr
Published on 2010-06-16T10:32:55Z Indexed on 2010/06/16 10:42 UTC
Read the original article Hit count: 140

Filed under:
|

The following code does not work correctly. How should it be done correctly?

for (std::set<Color>::iterator i = myColorContainer.begin();
            i!=myColorContainer.end();
            ++i)
{
    if ( *i  == Yellow)
    {
        DoSomeProccessing( *i );
        myColorContainer.erase(i);
    }
}

© Stack Overflow or respective owner

Related posts about stl

Related posts about set