C++字节流转字符串

直接上代码

所需头文件 : <string>, <stdio.h>, <stdint.h>

 1 std::string ByteStream2String(const uint8_t *pByteStream, size_t iStreamLen)
 2 {
 3   std::string sRet = "";
 4   char curr_byte[3];
 5 
 6   for (size_t idx = 0; idx < iStreamLen; ++idx)
 7   {
 8     memset(curr_byte, 0, 3);
 9     sprintf_s(curr_byte, "%02hhX", pByteStream[idx]);
10 
11     sRet += curr_byte;
12     sRet += " ";
13   }
14 
15   return sRet;
16 }

测试如下

运行结果如下

 

以上, 如有错误疏漏, 欢迎指正

posted @ 2020-10-22 11:18  public_tsing  阅读(1461)  评论(0编辑  收藏  举报