Skip to content
Related Articles

Related Articles

multiset size() in C++ STL with Examples
  • Difficulty Level : Expert
  • Last Updated : 23 Jul, 2018

The multiset::size() is a built-in function in C++ STL which returns the number of elements in the multiset container.

Syntax:

multiset_name.size()

Parameters: The function does not accept any parameters.

Return Value: The function returns the number of elements in the multiset container.

Below programs illustrate the above function:



Program 1:




// CPP program to demonstrate the
// multiset::size() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
  
    multiset<int> s;
  
    // Function to insert elements
    // in the multiset container
    s.insert(10);
    s.insert(13);
  
    cout << "The size of multiset: " << s.size();
    s.insert(13);
    s.insert(25);
  
    cout << "\nThe size of multiset: " << s.size();
    s.insert(24);
  
    cout << "\nThe size of multiset: " << s.size();
    return 0;
}
Output:
The size of multiset: 2
The size of multiset: 4
The size of multiset: 5

Program 2:




// CPP program to demonstrate the
// multiset::size() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
  
    multiset<int> s;
  
    cout << "The size of multiset: " << s.size();
    s.insert(2);
    s.insert(3);
  
    cout << "\nThe size of multiset: " << s.size();
    s.insert(4);
  
    cout << "\nThe size of multiset: " << s.size();
    return 0;
}
Output:
The size of multiset: 0
The size of multiset: 2
The size of multiset: 3

All functions of std::multiset

Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.
My Personal Notes arrow_drop_up
Recommended Articles
Page :