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

标准模板库