unordered_multimap emplace() function in C++ STL
The unordered_multimap::emplace() is a built-in function in C++ STL which inserts a new {key, element} in the unordered_multimap container. The insertion is done automatically at the position according to the container’s criterion. It increases the size of the container by one.
Syntax:
unordered_multimap_name.emplace(key, element)
Parameters: The function accepts a single mandatory parameter key and element which is to be inserted in the container.
Return Value: It returns an iterator which points to the newly inserted element.
Below programs illustrates the above function:
Program 1:
// C++ program to illustrate // unordered_multimap::emplace() #include <iostream> #include <string> #include <unordered_map> using namespace std; int main() { // declaration unordered_multimap<int, int> sample; // inserts key and elements sample.emplace(1, 2); sample.emplace(1, 2); sample.emplace(1, 3); sample.emplace(4, 9); sample.emplace(60, 89); cout << "Key and Elements: \n"; for (auto it = sample.begin(); it != sample.end(); it++) cout << "{" << it->first << ":" << it->second << "}\n "; return 0; } |
Key and Elements:
{60:89}
{4:9}
{1:3}
{1:2}
{1:2}
Program 2:
// unordered_multimap::emplace #include <iostream> #include <string> #include <unordered_map> using namespace std; int main() { // declaration unordered_multimap<string, string> sample; // inserts key and elements sample.emplace("gopal", "dave"); sample.emplace("gopal", "dave"); sample.emplace("Geeks", "C++"); sample.emplace("multimap", "functions"); sample.emplace("multimap", "functions"); cout << "Key and Elements: \n"; for (auto it = sample.begin(); it != sample.end(); it++) cout << "{" << it->first << ":" << it->second << "}\n "; return 0; } |
Key and Elements:
{multimap:functions}
{multimap:functions}
{Geeks:C++}
{gopal:dave}
{gopal:dave}
Recommended Posts:
- vector emplace() function in C++ STL
- unordered_multiset emplace() function in C++ STL
- list emplace() function in C++ STL
- unordered_set emplace() function in C++ STL
- map emplace() in C++ STL
- set::emplace() in C++ STL
- queue::emplace() in C++ STL
- emplace vs insert in C++ STL
- priority_queue emplace() in C++ STL
- multimap::emplace() in C++ STL
- deque emplace in C++ STL
- stack emplace() in C++ STL
- multiset::emplace() in C++ STL
- unordered_map emplace() in C++ STL
- Inserting elements in std::map (insert, emplace and operator [])
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.



