After deleting an item, iterators become invalid. It would be correct to write as follows (I replaced the for while with while , since you declared it out of the loop, and the while in this case looks better. Although it is better to use a for loop with an iterator declaration inside the loop)
while ( it != v.end() ) if (*it == "+"){ it = v.erase(it); } else { ++it; }
The general approach for such a task is written in one line.
#include <algorithm> #include <vector> #include <string> //... v.erase( std::remove( v.begin(), v.end(), "+" ), v.end() );
If you want to delete only one element, you can write it as follows:
auto it = std::find( v.begin(), v.end(), "+" ); if ( it != v.end() ) v.erase( it );