VOOZH about

URL: https://www.geeksforgeeks.org/cpp/how-to-insert-multiple-key-value-pairs-into-multimap-in-cpp/

⇱ How To Insert Multiple Key-Value Pairs Into a Multimap in C++? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How To Insert Multiple Key-Value Pairs Into a Multimap in C++?

Last Updated : 23 Jul, 2025

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-> Music

Add 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 Multimap

The below program demonstrates how we can insert multiple key-value pairs at a time in a multimap in C++ STL.


Output
Multimap 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