Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

multimap clear() function in C++ STL

  • Difficulty Level : Basic
  • Last Updated : 03 Aug, 2021

The multimap clear() function is an inbuilt function in C++ STL which is used to remove all elements from the multimap container (which are destroyed), leaving the container with a size of 0.
Syntax : 


Parameters: This function does not take any arguments.
Return Value: This function does not returns anything. The return type of the function is void. It just empties the whole container.
Below program illustrate the multimap::clear() function in C++: 

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

In case you wish to attend live classes with experts, please refer DSA Live Classes for Working Professionals and Competitive Programming Live for Students.


// CPP program to illustrate the
// multimap::clear() function
#include <cstring>
#include <iostream>
#include <map>
using namespace std;
int main()
    // Creating multimap of string and int
    multimap<string, int> mymultimap;
    // Inserting 3 Items with their value
    // using insert function
    mymultimap.insert(pair<string, int>("Item1", 10));
    mymultimap.insert(pair<string, int>("Item2", 20));
    mymultimap.insert(pair<string, int>("Item3", 30));
    cout << "Size of the multimap before using "
         << "clear function : ";
    cout << mymultimap.size() << '\n';
    // Removing all the elements
    // present in the multimap
    cout << "Size of the multimap after using"
         << " clear function : ";
    cout << mymultimap.size() << '\n';
    return 0;
Size of the multimap before using clear function : 3
Size of the multimap after using clear function : 0


Time Complexity : O(N), where N is the total number of elements in multimap.

My Personal Notes arrow_drop_up
Recommended Articles
Page :