Share via


deque::push_back

Adds an element to the end of the deque.

void push_back(
   const Type& _Val
);
void push_back(
   Type&& _Val
);

Parameters

Parameter

Description

_Val

The element added to the end of the deque.

Remarks

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

Code Example

// deque_push_back.cpp
// compile with: /EHsc
#include <deque>
#include <iostream>

int main( ) 
{
   using namespace std;
   deque <int> d;
   
   d.push_back( 1 );
   d.push_back( 2 );
   d.push_back( 3 );
   for( deque<int>::const_iterator i = d.begin(); i != d.end(); ++i )
   {
      cout << *i << " ";
   }
   cout << endl;

   d.push_front( 0 );
   d.push_back( 4 );
   for( deque<int>::const_iterator i = d.begin(); i != d.end(); ++i )
   {
      cout << *i << " ";
   }
   cout << endl;

// move initialize a deque of deques by moving d
   deque < deque <int> > dd;

   dd.push_back( move( d ) );
   cout << "Moved last element: " << dd[0].back( ) << endl;
}

Output

1 2 3
0 1 2 3 4
Moved last element: 4

Requirements

Header: <deque>

Namespace: std

See Also

Reference

deque Class

deque::push_back and deque::pop_back

Standard Template Library

Other Resources

deque Class Members