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
multimap
comparison operators
multimap::multimap
multimap::~multimap
member functions:
multimap::begin
multimap::clear
multimap::count
multimap::empty
multimap::end
multimap::equal_range
multimap::erase
multimap::find
multimap::get_allocator
multimap::insert
multimap::key_comp
multimap::lower_bound
multimap::max_size
multimap::operator=
multimap::rbegin
multimap::rend
multimap::size
multimap::swap
multimap::upper_bound
multimap::value_comp


multimap::find

public member function
      iterator find ( const key_type& x );
const_iterator find ( const key_type& x ) const;

Get iterator to element

Searches the container for an element with a value of x and returns an iterator to it if found, otherwise it returns an iterator to multimap::end (the element past the end of the container).

Notice that this function returns an iterator to only one of the elements with that value; To obtain the entire range of elements with a given value, you can use multimap::equal_range.

Parameters

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

Return value

An iterator to the element, if the specified key value is found, or multimap::end if the specified key is not found in the container.

Both iterator and const_iterator are member types. In the multimap class template, these are bidirectional iterators.
Dereferencing this iterator accesses the element's value, which is of type pair<const Key,T>.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// multimap::find
#include <iostream>
#include <map>
using namespace std;
int main ()
{
  multimap<char,int> mymm;
  multimap<char,int>::iterator it;
  mymm.insert (pair<char,int>('x',10));
  mymm.insert (pair<char,int>('y',20));
  mymm.insert (pair<char,int>('z',30));
  mymm.insert (pair<char,int>('z',40));
  it=mymm.find('x');
  mymm.erase (it);
  mymm.erase (mymm.find('z'));
  // print content:
  cout << "elements in mymm:" << endl;
  cout << "y => " << mymm.find('y')->second << endl;
  cout << "z => " << mymm.find('z')->second << endl;
  return 0;
}


Output:
elements in mymm:
y => 20
z => 40

Complexity

Logarithmic in size.

See also