Compartilhar via


list::push_back

Adds an element to the end of a list.

void push_back(

void push_back(
   Type&& _Val
);

Parameters

Parameter

Description

_Val

The element added to the end of the list.

Remarks

If an exception is thrown, the list is left unaltered and the exception is rethrown.

Example

// list_push_back.cpp
// compile with: /EHsc
#include <list>
#include <iostream>
#include <string>

int main( ) 
{
   using namespace std;
   list <int> c1;
   
   c1.push_back( 1 );
   if ( c1.size( ) != 0 )
      cout << "Last element: " << c1.back( ) << endl;

   c1.push_back( 2 );
   if ( c1.size( ) != 0 )
      cout << "New last element: " << c1.back( ) << endl;

// move initialize a list of strings
   list <string> c2;
   string str("a");

   c2.push_back( move( str ) );
   cout << "Moved first element: " << c2.back( ) << endl;
}
Last element: 1
New last element: 2
Moved first element: a

Requirements

Header: <list>

Namespace: std

See Also

Reference

list Class

Standard Template Library

Other Resources

list Class Members