vector::capacity
ベクターがより多くのメモリを追加割り当てせずに含めることのできる要素の数を返します。
size_type capacity( ) const;
戻り値
割り当てられているベクターの領域の現在の長さ。
解説
この項目を選択するために十分なメモリが割り当てられるメンバー関数 サイズ変更 が効率的です。割り当てられたメモリの総量を指定するには、メンバー関数 事前 を使用します。
使用例
// vector_capacity.cpp
// compile with: /EHsc
#include <vector>
#include <iostream>
int main( )
{
using namespace std;
vector <int> v1;
v1.push_back( 1 );
cout << "The length of storage allocated is "
<< v1.capacity( ) << "." << endl;
v1.push_back( 2 );
cout << "The length of storage allocated is now "
<< v1.capacity( ) << "." << endl;
}
必要条件
ヘッダー: <vector>
名前空間: std