C++ 打印十六进制数据,指定数据长度,前面不够时,补充0.
代码如下:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
unsigned int id = 0xc01;
unsigned int testCaseId = 0x80000c01;
cout << "id = 0x" << hex <<
setiosflags(ios::uppercase) <<
setw(6) << setfill('0') <<
id << endl;
cout << "testCaseId = 0x" << hex
<< setiosflags(ios::uppercase)
<< setw(6) << setfill('0')
<< testCaseId << endl;
return 0;
}
参考资料:
https://www.cnblogs.com/li-lou/p/12333817.html