Partager via


vector::reserve

Reserves a minimum length of storage for a vector object, allocating space if necessary.

void reserve(
   size_type _Count
);

Parameters

  • _Count
    The minimum length of storage to be allocated for the vector.

Example

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

Current capacity of v1 = 1
Current capacity of v1 = 20

Requirements

Header: <vector>

Namespace: std

See Also

Concepts

vector Class

vector Members

Standard Template Library