关于c++中进制输入输出
#include <iostream>
using namespace std;
void main()
{
int a = 010, b = 10, c = 0X10;//以0开头的数是八进制数,0X开头的是16进制数.
//以十进制显示数据;
cout << "DEC:" << endl;
//cout << dec;//要不要都可以,默认输出时以十进制输出;
cout << "a= " << a<<endl;
cout << "b = " << b<<endl;
cout << "c = " << c<<endl;
cout << endl;
cout << "OCT" << endl;
cout << oct; //指定八进制输出
cout << "a= " << a << endl;
cout << "b = " << b << endl;
cout << "c = " << c << endl;
cout << endl;
cout << "HEX" << endl;
cout << hex; //指定十六进制输出
cout << "a= " << a << endl;
cout << "b = " << b << endl;
cout << "c = " << c << endl;
//八,十和十六进制数混合运算并输出
cout << "a+b+c=";
cout << dec;
cout << a + b + c << endl;
//测试八,十和十六进制输入以及输出
cout << "DEC:a="; cin >>dec>> a;
cout << "OCT:b="; cin >>oct>>b;
cout << "HEX:a="; cin >>hex>>c;
//全部指定为八进制输出
cout <<oct<< "a=" << a << endl;
cout <<oct<< "b=" << b << endl;
cout <<oct<< "c=" << c << endl;
}
这是写的一个小的代码程序,有什么不懂得欢迎咨询,大家一起讨论,共同进步。