unordered_multiset find() function in C++STL

The unordered_multiset::find() is a built-in function in C++ STL which returns an iterator which points to the position which has the element val. If the element does not contain the element val, then it returns an iterator which points to a position past the last element in the container.

Syntax:

unordered_multiset_name.find(val)

Parameters: The function accepts a mandatory parameter val whose position’s iterator is to be returned.



Return Value: It returns an iterator which points to the position where val is.

Below programs illustrate the above function:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate the
// unordered_multiset::find() function
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
  
    // declaration
    unordered_multiset<int> sample;
  
    // inserts element
    sample.insert(100);
    sample.insert(100);
    sample.insert(100);
    sample.insert(200);
    sample.insert(500);
    sample.insert(500);
    sample.insert(600);
  
    // find the position of 500 and print
    auto it = sample.find(500);
    if (it != sample.end())
        cout << *it << endl;
    else
        cout << "500 not found\n";
  
    // find the position of 300 and print
    it = sample.find(300);
    if (it != sample.end())
        cout << *it << endl;
    else
        cout << "300 not found\n";
  
    // find the position of 100 and print
    it = sample.find(100);
    if (it != sample.end())
        cout << *it << endl;
    else
        cout << "100 not found\n";
  
    return 0;
}

chevron_right


Output:

500
300 not found
100

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate the
// unordered_multiset::find() function
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
  
    // declaration
    unordered_multiset<char> sample;
  
    // inserts element
    sample.insert('a');
    sample.insert('a');
    sample.insert('b');
    sample.insert('c');
    sample.insert('d');
    sample.insert('d');
    sample.insert('d');
  
    // find the position of 'a' and print
    auto it = sample.find('a');
    if (it != sample.end())
        cout << *it << endl;
    else
        cout << "a not found\n";
  
    // find the position of 'z' and print
    it = sample.find('z');
    if (it != sample.end())
        cout << *it << endl;
    else
        cout << "z not found\n";
  
    return 0;
}

chevron_right


Output:

a
z not found


My Personal Notes arrow_drop_up

The function of education is to teach one to think intensively and to think critically

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.