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

  1. //: C17:SmallString2.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. using namespace std;
  8.  
  9. int main() {
  10.   string s1
  11.     ("What is the sound of one clam napping?");
  12.   string s2
  13.     ("Anything worth doing is worth overdoing.");
  14.   string s3("I saw Elvis in a UFO.");
  15.   // Copy the first 8 chars
  16.   string s4(s1, 0, 8);
  17.   // Copy 6 chars from the middle of the source
  18.   string s5(s2, 15, 6);
  19.   // Copy from middle to end
  20.   string s6(s3, 6, 15);
  21.   // Copy all sorts of stuff
  22.   string quoteMe = s4 + "that" +  
  23.   // substr() copies 10 chars at element 20
  24.   s1.substr(20, 10) + s5 +
  25.   // substr() copies up to either 100 char
  26.   // or eos starting at element 5 
  27.   "with" + s3.substr(5, 100) +
  28.   // OK to copy a single char this way 
  29.   s1.substr(37, 1);
  30. } ///:~
  31.