home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C17 / StrSize.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  1.1 KB  |  34 lines

  1. //: C17:StrSize.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. #include <string>
  7. #include <iostream>
  8. using namespace std;
  9.  
  10. int main() {
  11.   string bigNews("I saw Elvis in a UFO. ");
  12.   cout << bigNews << endl;
  13.   // How much data have we actually got?
  14.   cout << "Size = " << bigNews.size() << endl;
  15.   // How much can we store without reallocating
  16.   cout << "Capacity = " 
  17.     << bigNews.capacity() << endl;
  18.   // Insert this string in bigNews immediately
  19.   // following bigNews[1]
  20.   bigNews.insert(1, " thought I ");
  21.   cout << bigNews << endl;
  22.   cout << "Size = " << bigNews.size() << endl;
  23.   cout << "Capacity = " 
  24.     << bigNews.capacity() << endl;
  25.   // Make sure that there will be this much space
  26.   bigNews.reserve(500);
  27.   // Add this to the end of the string
  28.   bigNews.append("I've been working too hard.");
  29.   cout << bigNews << endl;
  30.   cout << "Size = " << bigNews.size() << endl;
  31.   cout << "Capacity = " 
  32.     << bigNews.capacity() << endl;
  33. } ///:~
  34.