std::hex 导致放入流中的数据被打印为十六进制值。但是,用于表示数字 10 到 15 的字母 AF 总是以小写字母出现。有没有办法将其更改为使用大写字母?
有没有办法将其更改为使用大写字母?
是的,您可以应用std::uppercaseI/O 操纵器来更改默认行为(小写)。
上面提到的参考文献中的例子:
Run Code Online (Sandbox Code Playgroud)#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'; }输出:
Run Code Online (Sandbox Code Playgroud)0x2a with uppercase: 0X2A 0x2a with nouppercase: 0x2a 1e-10 with uppercase: 1E-10 1e-10 with nouppercase: 1e-10