gpt4 book ai didi

c++ - 为什么 C++ 在使用 std::hex 而不是大写时打印小写字母表?

转载 作者:太空狗 更新时间:2023-10-29 20:54:05 32 4
gpt4 key购买 nike

std::hex 使放入流中的数据打印为十六进制值。但是,用于表示数字 10 到 15 的字母 A-F 总是以小写字母出现。有没有办法将其改为使用大写字母?

最佳答案

Is there a way to change it to use capital letters instead?

是的,您可以申请 std::uppercase用于更改默认行为(小写)的 I/O 操纵器。

上述引用文献中的例子:

#include <iostream>
int main()
{
std::cout << std::hex << std::showbase
<< "0x2a with uppercase: " << std::uppercase << 0x2a << '\n'
<< "0x2a with nouppercase: " << std::nouppercase << 0x2a << '\n'
<< "1e-10 with uppercase: " << std::uppercase << 1e-10 << '\n'
<< "1e-10 with nouppercase: " << std::nouppercase << 1e-10 << '\n';
}

Output:

0x2a with uppercase: 0X2A
0x2a with nouppercase: 0x2a
1e-10 with uppercase: 1E-10
1e-10 with nouppercase: 1e-10

关于c++ - 为什么 C++ 在使用 std::hex 而不是大写时打印小写字母表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40414578/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com