cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : STL Containers : multiset : count
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
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 ( cont 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

// 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

multiset::find Get iterator to element (public member function)
multiset::equal_range Get range of equal elements (public member function)
multiset::size Return container size (public member function)
multiset::lower_bound Return iterator to lower bound (public member function)
multiset::upper_bound Return iterator to upper bound (public member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us