#include #include using namespace std; //******************************************************* // difference between character 2 and integer 2 // showing examples of modifiers: dec, hex, showbase, and setfill int main() { char ch = '2'; int i = 2; int j; cout << ch << " is a digit: " ; if (isdigit(ch)) cout << "yes" << endl; else cout << "no" << endl; cout << i << " is a digit: " ; if (isdigit(i)) cout << "yes" << endl; else cout << "no" << endl; cout << endl; cout << setfill('0'); cout << "IBM style:" << endl; cout << ch << " = x'" << hex << setw(2) << (int) ch << "'" << dec << endl; cout << i << " = x'" << hex << setw(2) << (int) i << "'" << dec << endl; cout << endl; cout << "Unix style:" << endl; cout << showbase; cout << ch << " = " << hex << setw(2) << (int) ch << dec << endl; cout << i << " = " << hex << setw(2) << (int) i << dec << endl; cout << endl << endl; // showpos i = 123; j = -123; cout << setfill(' '); cout << "default: " << setw(10) << i << setw(10) << j << endl; cout << showpos; cout << "showpos: " << setw(10) << i << setw(10) << j << endl; cout << noshowpos; cout << endl << endl; // showpoint float f1 = 123.; float f2 = -123.; cout << fixed << setprecision(0); cout << "fixed (0):" << setw(10) << f1 << setw(10) << f2 << endl; cout << showpoint; cout << "showpoint:" << setw(10) << f1 << setw(10) << f2 << endl; cout << noshowpoint; cout << endl; cout << scientific << setprecision(1); cout << "sci (1): " << setw(10) << f1 << setw(10) << f2 << endl; cout << showpoint; cout << "showpoint:" << setw(10) << f1 << setw(10) << f2 << endl; cout << noshowpoint; cout << endl; } /******************************************************* 2 is a digit: yes 2 is a digit: no IBM style: 2 = x'32' 2 = x'02' Unix style: 2 = 0x32 2 = 0x2 default: 123 -123 showpos: +123 -123 fixed (0): 123 -123 showpoint: 123. -123. sci (1): 1.2e+02 -1.2e+02 showpoint: 1.2e+02 -1.2e+02 */