我想要做:int a = 255; cout << a;并在输出中显示FF,我该怎么做?
3 回答

守候你守候我
TA贡献1802条经验 获得超10个赞
采用:
#include <iostream>
...
std::cout << std::hex << a;
还有许多其他选项可以控制输出数字的确切格式,例如前导零和大写/小写。

HUWWW
TA贡献1874条经验 获得超12个赞
std::hex
在被定义<ios>
,其由包括<iostream>
。但是要使用std::setprecision/std::setw/std::setfill
/ etc之类的东西,您必须包含<iomanip>
。

守着一只汪
TA贡献1872条经验 获得超3个赞
要操纵流以十六进制打印,请使用hex操纵器:
cout << hex << a;
默认情况下,十六进制字符以小写形式输出。要将其更改为大写,请使用uppercase操纵器:
cout << hex << uppercase << a;
若要稍后将输出更改回小写,请使用nouppercase操纵器:
cout << nouppercase << b;
没有找到匹配的内容?试试慕课网站内搜索吧
- 3 回答
- 0 关注
- 766 浏览
添加回答
举报
0/150
提交
取消