How To Insert Multiple Key-Value Pairs Into a Multimap in C++? Last Updated : 01 Mar, 2024 Comments Improve Suggest changes Like Article Like Report In C++, a multimap is similar to a map that stores the data in the key-value format and it also allows us to store duplicate keys for the same value. In this article, we will learn how to insert multiple Key-Value pairs efficiently into a multimap. Example: Input: multi_map = {{"Manas","Singing" }, {"Manas","Dancing" }} Output: Multimap after Insertion: Manas-> Singing Manas-> Dancing Salma-> Reading Salma-> Painting Salma-> Arts Soumya-> MusicAdd Multiple Key-Value Pairs in a Multimap in C++We can use the std::multimap::insert in C++ STL to insert elements in the std::multimap container by passing all the key-value pairs inside the insert() function at once. C++ Program to Add Multiple Key-Value Pairs in a MultimapThe below program demonstrates how we can insert multiple key-value pairs at a time in a multimap in C++ STL. C++ // C++ Program insert Multiple Items Into a Multimap #include <iostream> #include <map> using namespace std; int main() { multimap<string, string> hobbies = { { "Manas", "Singing" }, { "Manas", "Dancing" } }; // inserting multiple key-value pairs in a map hobbies.insert({ { "Salma", "Reading" }, { "Soumya", "Music" }, { "Salma", "Painting" }, { "Salma", "Arts" } }); // Displaying the elements pf multimap cout << "Multimap after Insertion: " << endl; for (const auto& key_value : hobbies) { string key = key_value.first; string value = key_value.second; cout << key << "-> " << value << endl; } return 0; } OutputMultimap after Insertion: Manas-> Singing Manas-> Dancing Salma-> Reading Salma-> Painting Salma-> Arts Soumya-> Music Time Complexity: O(M * log(N)), where N is the number of elements in the multimap and M is the number of elements to be inserted.Auxilliary Space: O(M) Comment More infoAdvertise with us Next Article How To Insert Multiple Key-Value Pairs Into a Multimap in C++? S sravankumar_171fa07058 Follow Improve Article Tags : C++ Programs C++ STL cpp-multimap CPP Examples +1 More Practice Tags : CPPSTL Similar Reads How to Insert into Multimap using make_pair in C++? In C++, a multimap is a container that stores key-value pairs in an ordered manner. Unlike a map, a multimap allows multiple values to be associated with a single key. In this article, we will learn how to insert into a multimap using make_pair in C++. Example Input: myMultimap = {{1, âC++â}, {2, âJ 2 min read How to Add Multiple Key-Value Pairs to a Map in C++? In C++, a map is a container that stores elements in key-value pairs, where each key is unique and associated with a value. In this article, we will learn how to add multiple key-value pairs to a map in C++. Example: Input: myMap = { {1, "one"} }; Elements to be insert = { {2, "two"}, {3, "three"}} 2 min read How To Delete Multiple Key-Value Pairs From Multimap in C++? In C++, a multimap is a container that stores elements where each element has a key value and a mapped value. Unlike maps, multimaps allow multiple key-value pairs with the same key. In this article, we will learn how to delete multiple key-value pairs from a multimap in C++. Example Input: myMultim 2 min read How to Insert Pairs into a Map in C++? In C++, maps are STL containers that store key-value pairs and maintain the element's order according to their keys. Pairs also store the data as key values. In this article, we will discuss how to insert a pair into a map in C++. For Example, Input: map<int, string> mp = {(1, "geek"), (2,"for 2 min read How to Insert a Pair in Multimap in C++? 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 2 min read Like