vector::shrink_to_fit

放弃多余的能力。

void shrink_to_fit(
);

示例

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

要求

标头: <vector>

命名空间: std

请参见

参考

vector Class

标准模板库