共用方式為


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

請參閱

參考

vector Class

vector::size 和 vector::capacity

標準樣板程式庫