multimap::operator= in C++ STL

In this article, we will be discussing the working, syntax, and example of multimap equal ‘=’ operator in C++ STL.

What is Multimap in C++ STL?

Multimaps are the associative containers, which are similar to map containers. It also facilitates storing the elements formed by a combination of key-value and mapped value in a specific order. In a multimap container, there can be multiple elements associated with the same key. The data is internally always sorted with the help of its associated keys.

What is multimap equal to ‘=’ operator?

multimap::operator= is equal to operator. This operator is used to copy the elements from one container to another container, by overwriting the current content of the container.


multiMap_name1 = multimap_name2;


There is a multimap on the left side of the operator and another multimap on the right side of the container. The contents of the right side are copied to the multimap on the left side.

Return value

There is no return value of an operator.


multimap<char, int> newmap, themap;
newmap.insert({1, 20});
newmap.insert({2, 30});
themap = newmap;


themap = 1:20 2:30


 Live Demo

using namespace std;
int main(){
   multimap<int,char > mul_1;
   multimap<int,char> mul_2;
   //declaring iterator to traverse the elements
   multimap<int,char>:: iterator i;
   //inserting elements to multimap1
   //inserting elements to multimap2
   //calling = operator
   mul_1= mul_2;
   //elements of multimap1
   cout<<"Elements in multimap1 are: "<<"\n";
   for( i = mul_1.begin(); i!= mul_1.end(); i++) {
      cout<<(*i).first<<" "<< (*i).second << "\n";
   //elements of multimap2
   cout<<"\nElements in multimap2 are: "<<"\n";
   for( i = mul_2.begin(); i!= mul_2.end(); i++) {
      cout<<(*i).first<<" "<< (*i).second << "\n";


If we run the above code it will generate the following output  −

Elements in multimap1 are:
4 e
5 f
6 g
Elements in multimap2 are:
4 e
5 f
6 g