C++ map emplace_hint() function
C++ map emplace_hint() function is used to extend the map container by inserting new elements into the container using hint as a position for element. Elements are built directly (neither copied nor moved).
The constructor of the element is called by giving the arguments args passed to this function. Insertion takes place only if the key is not present already.
args: The arguments forwarded to construct an element to be inserted into the map.
position: Hint for the position to insert the new elements.
It returns an iterator to the newly inserted elements. If the element already exists, insertion is failed and returns an iterator to the existing element.
Let's see a simple example to insert the elements into the map.
Map contains following elements a = 10 b = 20 c = 30 d = 40 e = 50
In the above example, it simply inserts the element into the map m with the given key value pairs and positions.
Let's see a simple example.
map starting data: 3 elements: (Rakesh,Accounting) (Ram,Accounting) (Sunil,Engineering) map modified, now contains 4 elements: (Deep,Engineering) (Rakesh,Accounting) (Ram,Accounting) (Sunil,Engineering)
Let's see a simple example to insert the elements into the map with the given position.
mymap contains: [a:12] [b:10] [c:14]
Let's see a simple example to insert the element.
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 in the beginning of the map.