Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

vector::push_back

Adds an element to the end of the vector.

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

Parameter

Description

_Val

The element added to the end of the vector.

// vector_push_back.cpp
// compile with: /EHsc
#include <vector>
#include <iostream>

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

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

// move initialize a vector of vectors by moving v1
   vector < vector <int> > vv1;

   vv1.push_back( move( v1 ) );
   if ( vv1.size( ) != 0 && vv1[0].size( ) != 0 )
      cout << "Newer last element: " << vv1[0].back( ) << endl;
}
Last element: 1
New last element: 2
Newer last element: 2

Header: <vector>

Namespace: std

Show:
© 2014 Microsoft. All rights reserved.