![]() |
In C++, we have multimap which is used to store key-value pairs like a map but multimap can have multiple values for the same key. In this article, we will learn how to insert a pair into a multimap in C++. Example Input: myMultimap = { {1, "this"}, {2,"is"}} myPair = {2, "was"}; Output: myMultimap = { {1, "this"}, {2,"is"}, {2, "was"}} Inserting Pairs into Multimap in C++To insert a pair into a multimap, we can use the std::multimap::insert() function that allows us to add the pair object to the multimap. First, create a multimap, then pass the pair you want to insert in the multimap to the insert() function. C++ Program to Insert Pair into MultimapThe below demonstrates the use of the insert() function to insert pairs into a multimap. C++
Output
1: One 1: Another One 2: Two Time Complexity: O(log N) We can also use emplace() function to insert pair into a multimap. |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |