进制转换———三行代码解决

为大家梳理一下I/O数据库提供的操作符

操纵符名 含义
dec 数值采用十进制表示
hex 数值采用十六进制表示
oct 数值采用八进制表示
endl 插入换行符
ends 终止字符串
setw 设置输出数据字段宽度为setw
setprecision(int) 设置浮点数小数点位数
#include<iostream>
#include<iomanip>//注意需包含文件头iomanip
using namespace std;
int main()
{
    
    
 int num;
 cin>>num;
 cout<<hex<<num<<endl;//将数值以16进制输出并换行
 cout<<cot<<num<<endl;//将数值以8进制输出并换行
 return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_46232829/article/details/107579425