且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Visual C ++中将字节数组转换为十六进制字符串?

更新时间:2021-12-06 06:26:07

正如您提到的c ++一样,这是一个答案. Iomanip用于将十六进制形式的整数存储到stringstream中.

As you have mentioned c++, here is an answer. Iomanip is used to store ints in hex form into stringstream.

#include <sstream>
#include <iomanip>

std::string hexStr(BYTE *data, int len)
{
     std::stringstream ss;
     ss << std::hex;

     for( int i(0) ; i < len; ++i )
         ss << std::setw(2) << std::setfill('0') << (int)data[i];

     return ss.str();
}