共用方式為


vector::push_back

將項目加入至的結尾。

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

參數

參數

描述

_Val

項目會加入至的結尾。

範例

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

需求

標題: <vector>

命名空間: std

請參閱

參考

vector Class

accumulate, copy, 和 vector::push_back

adjacent_difference 和 vector::push_back

vector::empty, vector::erase, 和 vector::push_back

vector::push_back 和 vector::pop_back

標準樣板程式庫