What happens in such traversal by iterators?
#include <string>
#include <map>
#include <iostream>
int main()
{
std::map<std::string, std::string> m;
m["aa"] = "AA";
m["bb"] = "BB";
m["cc"] = "CC";
m["dd"] = "DD";
int i = 0;
std::map<std::string, std::string>::iterator it = m.begin();
// for (; it != m.end(); it++) {
for (; it != m.end(); ) {
i++;
if (it->first.compare("bb") == 0) {
m.erase(it);
// m.erase(it->first);
continue;
}
// std::cout << it->first << "-->" << it->second << std::endl;
it++;
}
std::cout << "i: " << i << std::endl;
for (it = m.begin(); it != m.end(); it++) {
std::cout << it->first << "-->" << it->second << std::endl;
}
return 0;
}