multiset find() function in C++ STL Last Updated : 07 Jul, 2022 Comments Improve Suggest changes Like Article Like Report 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. Time complexity: If n is the size of multiset, then the time complexity of multiset::find() function is logarithmic order of n i.e. O(log(n)). Below program illustrates the above function. Program 1: CPP // 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; } Output: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 // 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; } Output:The set elements are: a a a a a b c c The set elements after b are: b c c Comment More infoAdvertise with us Next Article multiset count() function in C++ STL gopaldave Follow Improve Article Tags : Misc C++ STL CPP-Functions cpp-multiset +1 More Practice Tags : CPPMiscSTL Similar Reads Multiset in C++ STL In C++, multiset is an associative container similar to the set, but it can store multiple elements with same value. It is sorted in increasing order by default, but it can be changed to any desired order. It provides fast insertion, deletion and search operations.Example:C++#include <iostream 6 min read Commonly Used Methodsmultiset begin() and end() function in C++ STLThe multiset::begin() is a built-in function in C++ STL that returns an iterator pointing to the first element in the multiset container. Since multiset always contains elements in an ordered way, begin() always points to the first element according to the sorting criterion. Syntax: iterator multise 2 min read multiset size() in C++ STL with ExamplesThe multiset::size() is a built-in function in C++ STL which returns the number of elements in the multiset container. Syntax: multiset_name.size() Parameters: The function does not accept any parameters. Return Value: The function returns the number of elements in the multiset container. Below prog 2 min read multiset empty() function in C++ STLThe multiset::empty() function is a built-in function in C++ STL which checks if the multiset is empty or not. It returns true if the multiset is empty, else it returns false. Syntax: multiset_name.empty() Parameters: The function does not accept any parameter. Return Value: The function returns tru 1 min read multiset insert() function in C++ STLThe multiset::insert() is a built-in function in C++ STL which insert elements in the multiset container or inserts the elements from a position to another position from one multiset to a different multiset. Syntax: iterator multiset_name.insert(element)Time Complexity: O(log n) Since the elements a 4 min read multiset::emplace() in C++ STLMultisets are a type of associative containers similar to set, with an exception that multiple elements can have same values. multiset::emplace() This function is used to insert a new element into the multiset container. Syntax : multisetname.emplace(value) Parameters : The element to be inserted in 3 min read multiset find() function in C++ STLThe 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( 2 min read multiset count() function in C++ STLThe multiset::count() function is a built-in function in C++ STL that searches for a specific element in the multiset container and returns the number of occurrences of that element. Syntax: multiset_name.count(val) Parameters: The function accepts a single parameter val which specifies the element 2 min read multiset::erase() in C++ STLThe std::multiset::erase() is a built-in STL function used to remove elements from the multiset container. It is member function of std::multiset class defined inside <multiset> header file. In this article, we will learn about std::multiset::erase() in C++.The multiset::erase() function provi 3 min read multiset clear() function in C++ STLThe multiset::clear() function is a built-in function in C++ STL which removes all elements from the multiset container. The final size of multiset container after removal is 0. Syntax: multiset_name.clear() Parameters: The function does not accept any parameter. Return Value: The function does not 2 min read multiset::swap() in C++ STLMultisets are a type of associative containers similar to set, with an exception that multiple elements can have same values. multiset::swap() This function is used to exchange the contents of two multisets but the sets must be of same type, although sizes may differ. Syntax : multisetname1.swap(mul 3 min read Other Member Functionsmultiset lower_bound() in C++ STL with ExamplesThe multiset::lower_bound() is a built-in function in C++ STL which returns an iterator pointing to the first element in the container which is equivalent to k passed in the parameter. In case k is not present in the set container, the function returns an iterator pointing to the immediate next elem 3 min read multiset upper_bound() in C++ STL with ExamplesThe multiset::upper_bound() is a built-in function in C++ STL that returns an iterator pointing to the immediate next element which is just greater than k. If the key passed in the parameter exceeds the maximum key in the container, then the iterator returned points an element which points to the po 3 min read multiset max_size() in C++ STLThe multiset::max_size() is an observer function in C++ STL which returns the maximum number of elements a container can hold. This limit might be due to system or library implementations. Being an observer function it does not modify the multiset in any way. Syntax: multiset_name.max_size() Paramet 1 min read multiset::operator= in C++ STLMultisets are a type of associative containers similar to set, with an exception that multiple elements can have same values. multiset::operator= This operator is used to assign new contents to the container by replacing the existing contents. It also modifies the size according to the new contents. 3 min read multiset equal_range() function in C++ STLThe multiset::equal_range() is a built-in function in C++ STL which returns an iterator of pairs. The pair refers to the range that includes all the elements in the container which have a key equivalent to k. The lower bound will be the element itself and the upper bound will point to the next eleme 3 min read multiset emplace_hint() function in C++ STLThe multiset::emplace_hint() is a built-in function in C++ STL which inserts a new element in the multiset. A position is passed in the parameter of the function which acts as a hint from where the searching operation starts before inserting the element at its current position. The position only hel 3 min read multiset rbegin() and rend() function in C++ STLmultiset::rbegin() is a built-in function in C++ STL which returns a reverse iterator pointing to the last element in the multiset container. Syntax: reverse_iterator multiset_name.rbegin() Parameters: The function does not take any parameter. Return value: The function returns a reverse iterator po 2 min read multiset cbegin() and cend() function in C++ STLThe multiset::cbegin() is a built-in function in C++ STL which returns a constant iterator pointing to the first element in the container. The iterator cannot be used to modify the elements in the set container. The iterators can be increased or decreased to traverse the set accordingly. Syntax: con 3 min read multiset crbegin() and crend() function in C++ STLThe multiset::crbegin() is a built-in function in C++ STL which returns a constant reverse iterator pointing to the last element in the container. The iterator cannot be used to modify the elements in the multiset container. The iterators can be increased or decreased to traverse the set accordingly 2 min read multiset get_allocator() function in C++ STLThe multiset::get_allocator() method in C++ STL is a built-in function in C++ STL which returns a copy of the allocator object associated with the multiset. Syntax: multiset_name.get_allocator() where allocator_type is the type of the allocator used by the container. Parameters: The function does no 1 min read Multiset of Pairs in C++ with Examples What is Multiset? A multiset is an associative container that can hold a number of elements in a specific order. Unlike a set, a multiset can contain multiple occurrences of the same element. Some of the functions associated with a multiset: begin(): Returns an iterator to the first element in the m 4 min read Multiset of Vectors in C++ with Examples What is Multiset? A multiset in C++ is an associative container that can hold a number of elements in a specific order. Unlike a set, a multiset can hold multiple copies of the same element. Functions associated with a multiset: begin(): Returns an iterator to the first element in the multiset.end() 4 min read Multiset of Tuples in C++ with Examples What is a tuple? A tuple in C++ is an object which binds a group of elements together. The elements can be similar as well as different data types. The elements of tuples are initialized as in the order in which they will be accessed. Syntax: tuple<data_type1, data_type2, dataType3, ....> myTu 5 min read Multi-set for user defined data type You are given Q queries. Each query contains an integer k and a person's information i.e, first name, last name, age. For each query, we need to output Kth person among them if all person information are arrange in ascending order. Note: Person A comes before person B if first name of A is lexicogra 3 min read Like