Export (0) Print
Expand All
7 out of 11 rated this helpful - Rate this topic

vector::push_back

Adds an element to the end of the vector.

void push_back(
   const Type& _Val
);

Parameter

_Val
The element added to the end of the vector.

Example

// 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;
}

Output

Last element: 1
New last element: 2

See Also

vector Class | vector Members | accumulate, copy, and vector::push_back Sample | adjacent_difference, and vector::push_back Sample | vector::empty, vector::erase, and vector::push_back Sample | vector::push_back and vector::pop_back Sample

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.