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

  1. //: C18:Manips.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. // Format.cpp using manipulators
  7. #include <fstream>
  8. #include <iomanip>
  9. using namespace std;
  10.  
  11. int main() {
  12.   ofstream trc("trace.out");
  13.   int i = 47;
  14.   float f = 2300114.414159;
  15.   char* s = "Is there any more?";
  16.  
  17.   trc << setiosflags(
  18.          ios::unitbuf /*| ios::stdio */ /// ?????
  19.          | ios::showbase | ios::uppercase
  20.          | ios::showpos);
  21.   trc << i << endl; // Default to dec
  22.   trc << hex << i << endl;
  23.   trc << resetiosflags(ios::uppercase)
  24.     << oct << i << endl;
  25.   trc.setf(ios::left, ios::adjustfield);
  26.   trc << resetiosflags(ios::showbase)
  27.     << dec << setfill('0');
  28.   trc << "fill char: " << trc.fill() << endl;
  29.   trc << setw(10) << i << endl;
  30.   trc.setf(ios::right, ios::adjustfield);
  31.   trc << setw(10) << i << endl;
  32.   trc.setf(ios::internal, ios::adjustfield);
  33.   trc << setw(10) << i << endl;
  34.   trc << i << endl; // Without setw(10)
  35.  
  36.   trc << resetiosflags(ios::showpos)
  37.     << setiosflags(ios::showpoint)
  38.     << "prec = " << trc.precision() << endl;
  39.   trc.setf(ios::scientific, ios::floatfield);
  40.   trc << f << endl;
  41.   trc.setf(ios::fixed, ios::floatfield);
  42.   trc << f << endl;
  43.   trc.setf(0, ios::floatfield); // Automatic
  44.   trc << f << endl;
  45.   trc << setprecision(20);
  46.   trc << "prec = " << trc.precision() << endl;
  47.   trc << f << endl;
  48.   trc.setf(ios::scientific, ios::floatfield);
  49.   trc << f << endl;
  50.   trc.setf(ios::fixed, ios::floatfield);
  51.   trc << f << endl;
  52.   trc.setf(0, ios::floatfield); // Automatic
  53.   trc << f << endl;
  54.  
  55.   trc << setw(10) << s << endl;
  56.   trc << setw(40) << s << endl;
  57.   trc.setf(ios::left, ios::adjustfield);
  58.   trc << setw(40) << s << endl;
  59.  
  60.   trc << resetiosflags(
  61.          ios::showpoint | ios::unitbuf
  62.          // | ios::stdio // ?????????
  63.  );
  64. } ///:~
  65.