首页 > 代码库 > C++ cout的转换格式输出(八进制和十六进制)

C++ cout的转换格式输出(八进制和十六进制)

// hex,oct 输出
#include<iostream>

using namespace std;

int main()
{
	
	int chest = 42, waist = 42, inseam = 42;
	
	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;
	return 0;
}