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

  1. //: C18:Ostring.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. // Output strstreams
  7. #include <iostream>
  8. #include <strstream>
  9. using namespace std;
  10.  
  11. int main() {
  12.   const int sz = 100;
  13.   cout << "type an int, a float and a string:";
  14.   int i;
  15.   float f;
  16.   cin >> i >> f;
  17.   cin >> ws; // Throw away white space
  18.   char buf[sz];
  19.   cin.getline(buf, sz); // Get rest of the line
  20.   // (cin.rdbuf() would be awkward)
  21.   ostrstream os(buf, sz, ios::app);
  22.   os << endl;
  23.   os << "integer = " << i << endl;
  24.   os << "float = " << f << endl;
  25.   os << ends;
  26.   cout << buf;
  27.   cout << os.rdbuf(); // Same effect
  28.   cout << os.rdbuf(); // NOT the same effect
  29. } ///:~
  30.