C++ multiset - count() Function
The C++ multiset::count function returns the number of occurrences of an element in the multiset container.
Syntax
size_type count (const value_type& val) const;
size_type count (const value_type& val) const;
Parameters
val |
Specify value to search for. |
Return Value
Number of occurrences of the val in the multiset container.
Time Complexity
Logarithmic i.e, Θ(log(n)).
Example:
In the example below, the multiset::count function is used to find out the number of occurrences of specified element in the multiset called MyMSet.
#include <iostream> #include <set> using namespace std; int main (){ multiset<int> MyMSet{55, 25, 128, 5, 7, 5}; for(int i=5; i<10; i++) cout<<i<<" appeared "<<MyMSet.count(i)<<" times in the MyMSet.\n"; return 0; }
The output of the above code will be:
5 appeared 2 times in the MyMSet. 6 appeared 0 times in the MyMSet. 7 appeared 1 times in the MyMSet. 8 appeared 0 times in the MyMSet. 9 appeared 0 times in the MyMSet.
❮ C++ <set> Library