C ++: dec, hex and oct (decimal, hexadecimal, octal)

Detailed:

dec decimal as cout<<dec<<bwill be converted to decimal and then b output

The hex hexadecimal cout<<hex<<bwill convert to hexadecimal re-output b

As it is octal oct cout<<oct<<bwill 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();
}

Here Insert Picture Description
Reprinted from:
Reference 1
Reference 2
Reference 3
if wrong, private letters I, will immediately remove

Released three original articles · won praise 0 · Views 249

Guess you like

Origin blog.csdn.net/weixin_43991826/article/details/105187858