• Advertisement
Sign in to follow this  

Maps question

This topic is 3916 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

Real quick question, with maps (#include <map>) can you have multiple elements with the same value? For example, map.insert( pair<char,int>("a",20) ); map.insert( pair<char,int>("b",20) ); That's all, thanks

Share this post


Link to post
Share on other sites
Advertisement
Well, shouldn't take you more than 20 seconds to test it and find out.

Share this post


Link to post
Share on other sites
Yes, you can do what you have asked. The keys in your example are different, so each insert into the map will not collide with an already inserted element. If you want to be able to insert elements with the same key, then I believe you want to use a multimap.

Share this post


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

  • Advertisement