multiset count() function in C++ STL

The multiset::count() function is a built-in function in C++ STL which searches for a specific element in the multiset container and returns the number of occurrence of that element.

Syntax:

multiset_name.count(val)

Parameters: The function accepts a single parameter val which specifies the element to be searched in the multiset container.



Return Value: The function returns the count of elements which is equal to val in the multiset container.

Below programs illustrates the multimap::count() function:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// CPP program to demonstrate the
// multiset::count() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
  
    int arr[] = { 15, 10, 15, 11, 10, 18, 18, 20, 20 };
  
    // initializes the set from an array
    multiset<int> s(arr, arr + 9);
  
    cout << "15 occurs " << s.count(15)
         << " times in container";
  
    return 0;
}

chevron_right


Output:

15 occurs 2 times in container

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// CPP program to demonstrate the
// multiset::count() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
  
    int arr[] = { 15, 10, 15, 11, 10, 18, 18, 18, 18 };
  
    // initializes the set from an array
    multiset<int> s(arr, arr + 9);
  
    cout << "18 occurs " << s.count(18)
         << " times in container";
  
    return 0;
}

chevron_right


Output:

18 occurs 4 times in container


My Personal Notes arrow_drop_up

The function of education is to teach one to think intensively and to think critically

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.