如何使系统在十六进制数之前打印 0x,在八进制数之前打印 0?
How do I make the system print 0x before the hex number & 0 before the octal number?
我的老师说,对于作业,我们不允许在十六进制数字之前手动打印0x,我们必须让系统这样做。
目前我的代码如下所示:
cout << "Hex" << setw(12) << hex << static_cast<int>(letter) << setw(12) << hex
<< number << setw(12) << hex << static_cast<int> (symbol) << endl;
它打印正确的十六进制值,但没有 0x。
此外,对于八进制数字,我必须再次使系统在数字之前打印 0(不是手动。我的代码打印正确的值,但没有前面的 0:
cout << "Octal" << setw(12) << setbase(8) << static_cast<int>(letter) << setw(12) << setbase(8)
<< number << setw(12) << setbase(8) << static_cast<int>(symbol) << endl;
使用std::showbase
:
std::cout << std::hex << std::showbase << 1234567890;
相关文章:
- 用c++把小数点转换成八进制
- 如何使用 SML 随机生成八进制元组
- 编译器始终打印十六进制/八进制数字
- 在 C++ 中使用带有十六进制十进制和八进制数的 unsetf
- 十进制到八进制递归C++.以标准::字符串格式输出
- 在C++中,将无符号整数转换为八进制表示,反之亦然的最佳方法是什么
- 将字符串转换为十六进制数组c++
- 如何使系统在十六进制数之前打印 0x,在八进制数之前打印 0?
- 将大十六进制数转换为十进制形式(以 10 为基数的形式)的算法
- 为什么将字符串输出到未命名的 std::ofstream 反而给了我一个十六进制数?
- 如何在C++中使用setiosflags打印出十进制数作为八进制数
- 使用无符号字符数组输入十六进制数
- 用于"Ctrl + left arrow"和"Ctrl + right arrow"的八进制代码
- 将十六进制数作为主要函数参数
- 八进制文字怎么可能是负数?
- 在 c++ 中将八进制数变成实数
- 知道如何将八进制数转换为带有递归的小数
- 数组中的无效八进制数字是否有解决方法
- turbo八进制数在c++中的行为
- 为什么uint32_t的结果会自动变成八进制数?