Partager via


vector::shrink_to_fit

Ignore la capacité excédentaire.

void shrink_to_fit( );

Exemple

// vector_shrink_to_fit.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;
   v1.shrink_to_fit();
   cout << "Current capacity of v1 = " 
      << v1.capacity() << endl;
}
  

Configuration requise

En-tête : <vector>

Espace de noms : std

Voir aussi

Référence

vector, classe

Bibliothèque STL (Standard Template Library)