The multiset::find() is a built-in function in C++ STL which returns an iterator pointing to the lower_bound of the element which is searched in the multiset container. If the element is not found, then the iterator points to the position past the last element in the set.
Syntax:
multiset_name.find(element)
Parameters: The function accepts one mandatory parameter element which specifies the element to be searched in the multiset container.
Return Value: The function returns an iterator which points to the element which is searched in the multiset container. If the element is not found, then the iterator points to the position just after the last element in the multiset.
Below program illustrates the above function.
Program 1:
// CPP program to demonstrate the // multiset::find() function #include <bits/stdc++.h> using namespace std; int main() { // Initialize multiset multiset<int> s; s.insert(1); s.insert(4); s.insert(2); s.insert(5); s.insert(3); s.insert(3); s.insert(3); s.insert(5); cout << "The set elements are: "; for (auto it = s.begin(); it != s.end(); it++) cout << *it << " "; // iterator pointing to // position where 2 is auto pos = s.find(3); // prints the set elements cout << "\nThe set elements after 3 are: "; for (auto it = pos; it != s.end(); it++) cout << *it << " "; return 0; } |
The set elements are: 1 2 3 3 3 4 5 5 The set elements after 3 are: 3 3 3 4 5 5
Program 2:
// CPP program to demonstrate the // multiset::find() function #include <bits/stdc++.h> using namespace std; int main() { // Initialize multiset multiset<char> s; s.insert('a'); s.insert('a'); s.insert('a'); s.insert('b'); s.insert('c'); s.insert('a'); s.insert('a'); s.insert('c'); cout << "The set elements are: "; for (auto it = s.begin(); it != s.end(); it++) cout << *it << " "; // iterator pointing to // position where 2 is auto pos = s.find('b'); // prints the set elements cout << "\nThe set elements after b are: "; for (auto it = pos; it != s.end(); it++) cout << *it << " "; return 0; } |
The set elements are: a a a a a b c c The set elements after b are: b c c
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- multiset insert() function in C++ STL
- multiset equal_range() function in C++ STL
- multiset clear() function in C++ STL
- multiset empty() function in C++ STL
- multiset count() function in C++ STL
- multiset emplace_hint() function in C++ STL
- multiset rbegin() and rend() function in C++ STL
- multiset crbegin() and crend() function in C++ STL
- multiset cbegin() and cend() function in C++ STL
- multiset begin() and end() function in C++ STL
- multiset get_allocator() function in C++ STL
- multiset key_comp() function in C++ STL
- Multiset in C++ Standard Template Library (STL)
- multiset::operator= in C++ STL
- multiset::swap() in C++ STL
- multiset::emplace() in C++ STL
- multiset lower_bound() in C++ STL with Examples
- multiset upper_bound() in C++ STL with Examples
- multiset max_size() in C++ STL with Examples
- multiset size() in C++ STL with Examples
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.

