str2.cpp 723 B

1234567891011121314151617181920212223
  1. // str2.cpp -- capacity() and reserve()
  2. #include <iostream>
  3. #include <string>
  4. int main()
  5. {
  6. using namespace std;
  7. string empty;
  8. string small = "bit";
  9. string larger = "Elephants are a girl's best friend";
  10. cout << "Sizes:\n";
  11. cout << "\tempty: " << empty.size() << endl;
  12. cout << "\tsmall: " << small.size() << endl;
  13. cout << "\tlarger: " << larger.size() << endl;
  14. cout << "Capacities:\n";
  15. cout << "\tempty: " << empty.capacity() << endl;
  16. cout << "\tsmall: " << small.capacity() << endl;
  17. cout << "\tlarger: " << larger.capacity() << endl;
  18. empty.reserve(50);
  19. cout << "Capacity after empty.reserve(50): "
  20. << empty.capacity() << endl;
  21. // cin.get();
  22. return 0;
  23. }