次の方法で共有


vector::reserve

領域を割り当てる必要に応じてベクターのオブジェクトにストレージの最小の長さを予約します。

void reserve(
   size_type _Count
);

パラメーター

  • _Count
    ベクターに割り当てるストレージの最小の長さ。

使用例

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

int main( )
{
   using namespace std;   
   vector <int> v1;
   //vector <int>::iterator Iter;

   v1.push_back( 1 );
   cout << "Current capacity of v1 = " 
      << v1.capacity( ) << endl;
   v1.reserve( 20 );
   cout << "Current capacity of v1 = " 
      << v1.capacity( ) << endl;
}
  

必要条件

ヘッダー: <vector>

名前空間: std

参照

関連項目

vector Class

標準テンプレート ライブラリ