Skip to main content
gamedev.net
🔒 Locked

std::map problems

Started by fozed 3 replies 600+ views
Original Post
fozed
fozed
I need to get the key value for a std::map::iterator. How is this done? std::map<std::string,int> Age; Age["John"] = 31; Age["Jane"] = 20; Age["Someone else"] = 101; .... Later std::map<std::string, int>::iterator Iter = Age.begin(); Now how can you get the key value of Iter?
fozed
fozed
so Iter->first points to a std::string and Iter->second points to an int?
Prototype
Prototype
Also consider that iter points to a std::pair, which basically is the templated struct that holds first and second. This can be used in several functions, for example:
std::map<std::string, int> _map;std::pair<std::string, int> _pair;_pair.first = "foo";_pair.second = 42;_map.insert(_pair);

Hope that clears it up.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.