tags:

views:

100

answers:

1

Since maps dont allow duplicate values . Are there any other containers that are part of C++ standard library that allow duplicates that store values by key value pair?

+11  A: 

You can use std::multimap

Multimap is a Sorted Associative Container that associates objects of type Key with objects of type Data. multimap is a Pair Associative Container, meaning that its value type is pair. It is also a Multiple Associative Container, meaning that there is no limit on the number of elements with the same key.

Brian R. Bondy
Can I get values in sorted order using a multimap?
brett
Yes. Only std::unordered_map and std::unordered_multimap don't provide sorting.
Axel Gneiting
@brett: See the quoted text
Brian R. Bondy
By the way brett: `multimap` is usually in `<map>`, the interface is also the same. Just remember to use the `equal_range` member function when you search for something, otherwise you might forget some elements :)
Matthieu M.