Javatpoint Logo
Javatpoint Logo

C++ List assign()

C++ List assign() function assigns new contents to the list container and replaces the old one with a new one.

Syntax

Parameter

first,last: It defines the range of the elements that are to be copied.

n: It specifies the new size of the container.

val: New value which is to added in a newly constructed space.

Return value

It does not return any value.

Example 1

Let's see a simple example

Output:

10 10 10

In this example, assign() function replaces the old content with a new content. It assigns '10' value 3 times in the list container.

Example 2

Let's see a simple example

Output:

C++

In this example, assign() function assigns the first list to the second list.


Next Topicemplace() Function



Please Share

facebook twitter google plus pinterest