源码来自《C++ Primer Plus》,有微小改动,运行于64位win10
#include <iostream>
using namespace std;
int main() {
int chest = 42;
int waist = 0x42;
int inseam = 042;
cout << "Monsieur cuts a striking figure!\n";
cout << "Chest = " << chest << " (42 in decimal)\n";
cout << "Waist = " << waist << " (0x42 in hex)\n";
cout << "Inseam = " << inseam << " (042 in octal)\n";
cout << endl;
cout << "Monsieur cuts a striking figure again!\n";
cout << "Chest = " << chest << " (decimal for 42)\n";
cout << hex;
cout << "Waist = " << waist << " (hexadecimal for 42)\n";
cout << oct;
cout << "Inseam = " << inseam << " (octal for 42)\n";
return 0;
}
Output:
Monsieur cuts a striking figure!
Chest = 42 (42 in decimal)
Waist = 66 (0x42 in hex)
Inseam = 34 (042 in octal)
Monsieur cuts a striking figure again!
Chest = 42 (decimal for 42)
Waist = 42 (hexadecimal for 42)
Inseam = 42 (octal for 42)