Detailed:
dec decimal as cout<<dec<<b
will be converted to decimal and then b output
The hex hexadecimal cout<<hex<<b
will convert to hexadecimal re-output b
As it is octal oct cout<<oct<<b
will convert into an octal re-output b
Example 1:
#include<iostream>
using namespace std;
int main() {
int n = 16;
cout << dec << n << endl;
cout << oct << n << endl;
cout << hex << n << endl;
return 0;
}
//输出:16 20 10
Example 2:
The default format is decimal dec, before modifying the format of the original format will remain in effect. Use hex and octal hexadecimal format decimal value oct 42
void hexoct2(void)
{
int chest=42;
int waist=42;
int inseam=42;
cout<<"monsieur cuts a striking figure!"<<endl;
cout<<"chest="<<chest<<" (decimal for 42)"<<endl;
cout<<hex;//manipulator for changing number base
cout<<"waist="<<waist<<" (hexadecimal for 42)"<<endl;
cout<<oct;//manipulator for changing number base
cout<<"inseam="<<inseam<<" (octal for 42)"<<endl;
cin.get();
}
Reprinted from:
Reference 1
Reference 2
Reference 3
if wrong, private letters I, will immediately remove