C++ multimap insert() functionThe C++ multimap insert() is used to insert an element or range of elements into a multimap. SyntaxParameterval: Key value to insert in the multimap. position: Hint for the position to insert element. first: Beginning of range to insert. last: End of range to insert. il: An initializer list. Return valueIf a single element is inserted then it returns an iterator to the position where the new element was inserted into the multimap. Or if the element is inserted with hint then it returns an iterator that point to the position where the new element was inserted into the multimap. Complexity
Iterator validityNo changes. Data RacesThe container is modified. Exception safetyThis function does not throw exception. Example 1Let's see the simple example to insert the elements into the multimap: Output: Multimap contains following elements a = 1 b = 2 b = 3 c = 4 c = 5 In the above example, it simply insert the element with the given key value pair. Example 2Let's see a simple example to insert the element in the specified position: Output: Multimap contains following elements a = 1 b = 2 c = 3 d = 4 d = 5 In the above example, elements are inserted in the defined position i.e. in begin element {'a', 1} is inserted and in the end element {'d', 5} is inserted. Example 3Let's see a simple example to insert the elements of one multimap to another: Output: Multimap contains following elements a = 1 a = 3 b = 2 b = 5 d = 4 In the above example, multimap m1 has five elements and multimap m2 is empty. insert() is using to insert the element of m1 to m2 from begin of m1 to end of m1 and displaying the content of m2 multimap. Example 4Let's see a simple example to insert the element: Output: Multimap contains following elements 1 : Java 2 : C++ 3 : SQL 3 : Oracle 4 : VB In the above example, another form of insert() function is used to insert the elements into the multimap. 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