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 :
mymultimap_name.clear()
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++:
C++
#include <cstring>
#include <iostream>
#include <map>
using namespace std;
int main()
{
multimap<string, int > mymultimap;
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' ;
mymultimap.clear();
cout << "Size of the multimap after using"
<< " clear function : " ;
cout << mymultimap.size() << '\n' ;
return 0;
}
|
OutputSize 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.