Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
STL Containers
bitset
deque
list
map
multimap
multiset
priority_queue
queue
set
stack
vector
multiset
comparison operators
multiset::multiset
multiset::~multiset
member functions:
multiset::begin
multiset::clear
multiset::count
multiset::empty
multiset::end
multiset::equal_range
multiset::erase
multiset::find
multiset::get_allocator
multiset::insert
multiset::key_comp
multiset::lower_bound
multiset::max_size
multiset::operator=
multiset::rbegin
multiset::rend
multiset::size
multiset::swap
multiset::upper_bound
multiset::value_comp


multiset::count

public member function
size_type count ( const key_type& x ) const;

Count elements with a specific key

Searches the container for an element with a key of x and returns the number of times the element appears in the container.

Parameters

x
Value to be searched for.
key_type is a member type defined in multiset containers as an alias of Key, which is the first template parameter and the type of the elements stored in the container.

Return value

The amount of elements in the container with a key value equivalent to x.

Member type size_type is an unsigned integral type.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// multiset::count
#include <iostream>
#include <set>
using namespace std;
int main ()
{
  int myints[]={10,73,12,22,73,73,12};
  multiset<int> mymultiset (myints,myints+7);
  cout << "73 appears ";
  cout << (int) mymultiset.count(73);
  cout << " times in mymultiset." << endl;
  return 0;
}


Output:
73 appears 3 times in mymultiset.

Complexity

Logarithmic in size plus linear in the count.

See also