multiset::clear() method in C++ STL

Multisets are associative containers available in the C++ Standard Library. They are similar to sets with an addition that multiple keys with equivalent values are allowed. The multiset::clear() is a method available in the STL that removes all elements from the container.

Syntax:

set_name.clear();

Parameters: The multiset::clear() does not accept any parameter:
Return value: none

Example of multiset::clear() method

#include <iostream>
#include <set>

using namespace std;

int main()
{
   multiset<int> m;
   m.insert(1);
   m.insert(2);
   m.insert(3);
   m.insert(4);
   
  cout<<m.size()<<endl;
  
  m.clear();
  cout<<"Size after clear: "<<m.size();
}

Output:

4
Size after clear: 0

This article is written by

Please comment below, if you have any doubts or find any error in the above article.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top