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 }

测试如下

运行结果如下

 

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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM