home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_11_07 / 1107105a < prev    next >
Text File  |  1993-05-04  |  743b  |  35 lines

  1. // base1.cpp:    Shows the bases of integers
  2. #include <iostreams.h>
  3.  
  4. main()
  5. {
  6.     int x, y, z;
  7.  
  8.     cout << "Enter three ints: ";    
  9.     cin >> x >> y >> z;
  10.     cout << x << ',' << y << ',' << z << endl;
  11.     
  12.     // Print in different bases
  13.     cout << x << ',';
  14.     cout.setf(ios::oct,ios::basefield);
  15.     cout << y << ',';
  16.     cout.setf(ios::hex,ios::basefield);
  17.     cout << z << endl;
  18.     
  19.     // Show the base prefix
  20.     cout.setf(ios::showbase);
  21.     cout << x << ',';
  22.     cout.setf(ios::oct,ios::basefield);
  23.     cout << y << ',';
  24.     cout.setf(ios::hex,ios::basefield);
  25.     cout << z << endl;
  26.     return 0;
  27. }
  28.  
  29. // Sample Execution
  30. // Enter three ints: 10 010 0x10
  31. // 10,8,16
  32. // 10,10,10
  33. // 0xa,010,0x10
  34.  
  35.