Partager via


list::push_front

Adds an element to the beginning of a list.

void push_front(
   const Type& _Val
);

Parameters

  • _Val
    The element added to the beginning of the list.

Remarks

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

Example

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

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

   c1.push_front( 2 );
   if ( c1.size( ) != 0 )
      cout << "New first element: " << c1.front( ) << endl;
}

First element: 1
New first element: 2

Requirements

Header: <list>

Namespace: std

See Also

Concepts

list Class

list Class Members

Standard Template Library