Javatpoint Logo
Javatpoint Logo

C++ List emplace()

C++ List emplace() function inserts new element at a specified position and the size of the list is increased by one.

Syntax

Parameter

pos: It defines the position where the new element is to be inserted.

val: New value to be inserted at a specified position.

Return value

It returns an iterator pointing to the newly constructed element.

Example 1

Let's see a simple example when the new element is inserted in between the list.

Output:

java

In this example, emplace() function adds a new character at second position

Example 2

Let's see a simple example when the new element is added at the end of the list.

Output:

java is a programming language 

In this example, emplace() function adds a new string i.e "programming language" at the end of the list.





Please Share

facebook twitter google plus pinterest