• Advertisement
Sign in to follow this  

stl map question

This topic is 4666 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Couple of ways, you can use the index operator:

mymap[key]

the problem here is: if there is no element with the key "key" then it will create one with a default value.

mapiterator = mymap.find(key);

this will return an iterator to the entry with the key "key", or to mymap.end() should it not exist.

Share this post


Link to post
Share on other sites
thanks. what I meant was how can i access the nth element that was added to a map?

cheers

Share this post


Link to post
Share on other sites
Maps are sorted. Unless you added the elements in a sorted order, you can't access the n'th element inserted. You could iterate over the map to the n'th element in the map.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement