Using STL Map

Sage
Posts: 1,066
Joined: 2004.07
Post: #1
I'm considering using the STL map structure for a project but I'm not sure if I can do what I would like to do. Is it possible to use an interator and step through the map, printing out both the key and the value? I know how to easily get the value, but I'm not sure if you can get the key using an iterator or not.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Code:
std::map<K, V>::const_iterator e = my_map.end();
for (std::map<K, V>::const_iterator i = my_map.begin(); i != e; ++i) {
    K key = (*i).first;
    V value = (*i).second;
}
Quote this message in a reply
Post Reply