Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library


The C++ unordered_multiset::count function is used to return the number of occurrences of an element in the unordered_multiset container.

Syntax

size_type count (const key_type& k) const;

Parameters

k Specify value to search for.

Return Value

Number of occurrences of the specified element in the unordered_multiset container.

Time Complexity

Average case: Linear in number of elements counted.
Worst case: Linear in container size.

Example:

In the below example, the unordered_multiset::count function is used to find out the number of occurrences of specified element in uMSet.

#include <iostream>
#include <unordered_set>
using namespace std;
 
int main (){
  unordered_multiset<int> uMSet{55, 25, 128, 5, 7, 5};

  for(int i=5; i<10; i++)
    cout<<i<<" appeared "<<uMSet.count(i)<<" times in the uMSet.\n";

  return 0;
}

The output of the above code will be:

5 appeared 2 times in the uMSet.
6 appeared 0 times in the uMSet.
7 appeared 1 times in the uMSet.
8 appeared 0 times in the uMSet.
9 appeared 0 times in the uMSet.

❮ C++ - Unordered Multiset