直接上代码

所需头文件 : <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 }

测试如下

C++字节流转字符串

运行结果如下

C++字节流转字符串

 

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

相关文章:

  • 2021-06-20
  • 2022-12-23
  • 2022-12-23
  • 2021-05-29
  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
  • 2021-09-27
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-28
  • 2021-11-02
  • 2022-12-23
  • 2021-10-01
相关资源
相似解决方案