Be careful in comparing the find result with the the end like for map 'm' as all answer have done above map::iterator i = m.find("f");
if (i == m.end()) { } else { }
you should not try and perform any operation such as printing the key or value with iterator i if its equal to m.end() else it will lead to segmentation fault.