您的位置:首页 > 编程语言 > C语言/C++

C++ cout利用控制符dec、hex和oct,分别输出十进制、十六进制和八进制显示整数

2015-07-02 22:28 701 查看
使用hex和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();
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: