Skip to content
Related Articles

Related Articles

Improve Article

multimap size() function in C++ STL

  • Difficulty Level : Basic
  • Last Updated : 29 Jun, 2018

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



Parameters: The function does not accept any parameter.

Return Value: This function returns the number of elements a multimap container has.

// C++ function for illustration
// multimap::size() function
#include <bits/stdc++.h>
using namespace std;
int main()
    // initialize container
    multimap<int, int> mp;
    // insert elements in random order
    mp.insert({ 2, 30 });
    mp.insert({ 1, 40 });
    mp.insert({ 2, 60 });
    mp.insert({ 2, 20 });
    mp.insert({ 1, 50 });
    mp.insert({ 4, 50 });
    cout << "multimap mp has " << mp.size()
         << " number of elements";
    return 0;
multimap mp has 6 number of elements
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 :