Say I have a map
map<string, string> m;
And do a
string x = m["asdf"];
without knowing if “asdf” is in the map or not. Then I won’t be able to reliably figure out if it was in the map or not by looking at x. Is that correct?
So I should have done a m.first(asdf) first to figure this out.
The
map::operator[]inserts the key in the map with a default value, if not there.If you do not want that:
The
map::operator[]is useful for many things, particularly with references. For example:That will add an
"X"to the (possibly newly created) string in the map.