Multisets are associative containers available in the C++ Standard Library. They are similar to sets with an addition that multiple keys with equivalent values are allowed. The multiset::find()
is a method available in the STL that searches the set and returns an iterator to the first occurrence of a specific key if found.
Syntax:
set_name.find( key );
Parameters: The multiset::find()
accepts a single parameter:
• key: Key to search for
Return value: An iterator to the element with the given key. multiset::end()
otherwise
Example of multiset::find() method
#include <iostream> #include <set> using namespace std; int main() { multiset<int> m; m.insert(1); m.insert(2); m.insert(2); m.insert(2); m.insert(3); m.insert(4); cout<<"Index of key 4 is: "<<distance(m.begin(), m.find(4)); }
Output:
Index of key 4 is: 5