home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / tybc4 / out1.cpp < prev    next >
C/C++ Source or Header  |  1993-03-24  |  743b  |  27 lines

  1. // Program illustrates C++ formatted stream output
  2. // using the width and precision functions
  3.  
  4. #include <iostream.h>
  5.  
  6. main()
  7. {
  8.   short    aShort     = 4;
  9.   int      anInt      = 67;
  10.   unsigned char aByte = 128;
  11.   char     aChar      = '@';
  12.   float    aSingle    = 355.0;
  13.   double   aDouble    = 1.130e+002;
  14.   // display sample expressions
  15.   cout.width(3); cout << int(aByte) << " + ";
  16.   cout.width(2); cout << anInt << " = ";
  17.   cout.width(3); cout << (aByte + anInt) << '\n';
  18.  
  19.   cout.precision(4); cout << aSingle << " / ";
  20.   cout.precision(4); cout << aDouble << " = ";
  21.   cout.precision(5); cout << (aSingle / aDouble) << '\n';
  22.  
  23.   cout << "The character in variable aChar is "
  24.        << aChar << '\n';
  25.   return 0;
  26. }
  27.