English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C++ List push_back() Usage and Example

C++ List (List)

C ++ List push_back() inserts a new element at the end of the list, and the size of the list container increases1.

The push_back() function inserts elements at the end5.

Syntax

Assuming an element is " x":

push_back(const value_type& x);

Parameter

x: It is the end of the value to be inserted.

Return value

It does not return any value.

Example1

Let's see a simple example

#include<iostream>  
#include<list>  
using namespace std;  
int main()
{
   listli={"C"," .Net"++," .Net "];
   list::iterator itr;
   li.push_back(" java ");
   li.push_back(" PHP ");
  for(itr=li.begin();itr!=li.end();++itr)
   cout<<*itr;
    return 0;
}

Output:

C C++  .Net java PHP

In this example, the push_back() function inserts two strings, java and PHP, at the end of the list.

Example2

Let's see a simple example

#include<iostream>  
#include<list>  
using namespace std;  
int main()
{
   list li={6,7,8,9};
   list::iterator itr;
   li.push_back(10);
   li.push_back(11);
  for(itr=li.begin();itr!=li.end();++itr)
   cout<<*itr<<","
   return 0;
}

Output:

6,7,8,9,10,11

C++ List (List)