c++ hex 十六进制输出 0字符占位

来源:互联网 发布:德尔塔高达淘宝 编辑:程序博客网 时间:2024/06/02 05:31
// c++
#include <iostream>
#include <iomanip>
void r_coutHex(const unsigned char * p,int len)
{
int i = 0;
for (; i<len; i++)
{
std::cout<<std::hex<<std::setw(2)<<std::setfill('0')<<(unsigned int)(p[i])<<" ";
}
std::cout<<std::endl;

}


参考:http://en.cppreference.com/w/cpp/io/manip/setfill

运行结果如下图:第2个框,输入自传入哈(博客传图失败,汗)

5a a5 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 20 ff a3 5e


===========================================================================

补充 C 语言 的十六进制输出占位 0

超级简单

printf("%03x",para); //输出 3个字符宽的十六进制。不足补0

printf("%6s",str);//再啰嗦一下 6个字符的固定长度输出。可以意会了哇



1 0
原创粉丝点击