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