How to update the value of a key in std::map after using the find method?
I have a map and iterator declaration like this:
std::map::find returns an iterator to the found element (or to the end() if the element was not found). So long as the map is not const, you can modify the element pointed to by the iterator:
std::map m;
m.insert(std::make_pair('c', 0)); // c is for cookie
std::map::iterator it = m.find('c');
if (it != m.end())
it->second = 42;