I think you want map::find
. If m.find("f")
is equal to m.end()
, then the key was not found. Otherwise, find returns an iterator pointing at the element found.
The error is because p.first
is an iterator, which doesn't work for stream insertion. Change your last line to cout << (p.first)->first;
. p
is a pair of iterators, p.first
is an iterator, p.first->first
is the key string.
A map can only ever have one element for a given key, so equal_range
isn't very useful. It's defined for map, because it's defined for all associative containers, but it's a lot more interesting for multimap.