我知道如何使它成为十六进制:
unsigned char myNum = 0xA7;
clog << "Output: " std::hex << int(myNum) << endl;
// Gives:
// Output: A7
现在,如果 myNum 只需要一位数字,我希望它始终打印前导零:
unsigned char myNum = 0x8;
// Pretend std::hex takes an argument to specify number of digits.
clog << "Output: " << std::hex(2) << int(myNum) << endl;
// Desired:
// Output: 08
那么我该怎么做呢?