Programming Tips - Can I get an a iterator that points to the item I just inserted into a map?

Date: 2007dec6 Language: C/C++ Keywords: insert Q. Can I get an a iterator that points to the item I just inserted into a map? A. Yes. Here's how: Microsoft Visual C++:
#include <map> #include <string> typedef std::map<std::string, int> MYMAP; MYMAP mymap; MYMAP::_Pairib result; MYMAP::iterator it; // insert() returns a pair result = mymap.insert(MYMAP::value_type("hello", 4)); it = result.first; // Now you can use "it", an iterator pointing to the just inserted item
Borland C++ 5.02:
std::pair<MYMAP::iterator, bool> result = mymap.insert(MYMAP::value_type("hello", 4)); it = result.first;