C++ multimap emplace() functionThe C++ multimap emplace() function is used to extend the multimap container by inserting new elements into the container. Elements are built directly (neither copied nor moved). The constructor of the element is called by giving the arguments args passed to this function. SyntaxParameterargs: The arguments forwarded to construct an element to be inserted into the multimap. Return valueThe C++ emplace() function indicates if the insertion is occurred or not and returns an iterator pointing to the newly inserted element. ComplexityLogarithmic in the container size. Iterator validityNo changes. Data racesThe container is modified. Iterating ranges in the container is not safe although concurrently accessing exiting elements is safe. Exception SafetyIf an exception is thrown, there are no changes in the container. Example 1Let's see the simple example to insert the elements into the multimap: Output: Multimap contains following elements a = 1 b = 2 b = 4 c = 3 c = 5 In the above example, it simply insert the element into the multimap m with the given key value pairs. Example 2Let's see a simple example to insert the element and check whether the duplicate key is allowed in multimap or not: Output: multimap modified, now contains 3 elements: (Amita,Accounting) (Deep,Engineering) (Nikita,Accounting) multimap modified, now contains 4 elements: (Amita,Accounting) (Deep,Engineering) (Nikita,Accounting) (Nikita,Engineering) In the above example, elements are inserted in the multimap and when you try to add the same key Nikita then it will allow you to insert duplicates. Example 3Let's see a simple example to insert the elements into the multimap by passing a constructor argument to a key and a value respectively: Output: a => a a => aaa b => abcd c => cccccccccc In the above example, elements are inserted into the multimap by passing a constructor argument to a key and a value respectively. Example 4Let's see a simple example to insert the element: Output: Enter the number of fmly members : 3 Enter the name and age of each member: Ram 42 Sita 37 Laxman 40 Total memnber of fmly is:3 Details of fmly members: Name | Age __________________________ Laxman | 40 Ram | 42 Sita | 37 In the above example, it simply inserts the elements by the user's choice. Next TopicC++ multimap |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India