| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 
 | // string::shrink_to_fit
#include <iostream>
#include <string>
int main ()
{
  std::string str (100,'x');
  std::cout << "1. capacity of str: " << str.capacity() << '\n';
  str.resize(10);
  std::cout << "2. capacity of str: " << str.capacity() << '\n';
  str.shrink_to_fit();
  std::cout << "3. capacity of str: " << str.capacity() << '\n';
  return 0;
}
 |