cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : STL Containers : multiset : find
- -
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::find public member function
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 multiset::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 multiset::equal_range.

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

An iterator to one of the elements with that value, if such an element is found, or multiset::end if the specified value is not found in the container.
iterator is a member type, defined in multiset as a bidirectional iterator type.

Example

// multiset::find
#include <iostream>
#include <set>
using namespace std;

int main ()
{
  multiset<int> mymultiset;
  multiset<int>::iterator it;

  // set some initial values:
  for (int i=1; i<=5; i++) mymultiset.insert(i*10);   // 10 20 30 40 50

  it=mymultiset.find(20);
  mymultiset.erase (it);
  mymultiset.erase (mymultiset.find(40));

  cout << "mymultiset contains:";
  for (it=mymultiset.begin(); it!=mymultiset.end(); it++)
    cout << " " << *it;
  cout << endl;

  return 0;
}

Output:

mymultiset contains: 10 30 50

Complexity

Logarithmic in size.

See also

multiset::equal_range Get range of equal elements (public member function)
multiset::count Count elements with a specific key (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