C++ Standard Library C++ STL Library

C++ multiset - find() Function



The C++ multiset::find function is used to search the container for an element equivalent to the specified value and returns the iterator to it if found, else returns the iterator to multiset::end.

Syntax

iterator find (const value_type& val) const;
const_iterator find (const value_type& val) const;
iterator find (const value_type& val);

Parameters

val Specify value to search for.

Return Value

An iterator to the element if val is found, or multiset::end if val is not found.

Time Complexity

Logarithmic i.e, Θ(log(n)).

Example:

In the example below, the multiset::find function is used to find the element in the multiset called MyMSet.

#include <iostream>
#include <set>
using namespace std;
 
int main (){
  multiset<int> MyMSet{55, 25, 128, 5, 72};
  multiset<int>::iterator it;

  it = MyMSet.find(25);
  MyMSet.erase(it);
  MyMSet.erase(MyMSet.find(5));

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

  return 0;
}

The output of the above code will be:

MyMSet contains: 55 72 128 

❮ C++ <set> Library