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
2010-07-06 23:38:31
Can I get values in sorted order using a multimap?
brett
2010-07-06 23:39:11
Yes. Only std::unordered_map and std::unordered_multimap don't provide sorting.
Axel Gneiting
2010-07-06 23:40:29
@brett: See the quoted text
Brian R. Bondy
2010-07-06 23:41:35
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.
2010-07-07 08:09:04