I am using a std::multimap
std::multimap<string,string> map;
It contains elements below
1 2
2 3
3 2
1 2
1 0
I want to replace all 1's and 2's by X. I searched in google for a long time, but didn't get the result. I tried like
for(it=mmap.begin();it!=mmap.end();it++)
{
if(it->first == "1" || it->first == "2")
{
key = it->second;
it.erase(it);
mmap.insert(pair<string,string>("X",key));
}
}
but ended up in wrong result . I understand the size varies each time and when we insert the element gets inserted at the end which in turn ends the for loop. any other way to come out of this?