如何将一组十六进制字符串转换为字节数组

Dea*_*ean 5 c++

我有一个char的输入 *str = "13 00 0A 1B CA 00";

我需要一个输出 BYTE bytes[] = { 0x13, 0x00, 0x0A, 0x1B, 0xCA, 0x00 };

有人可以帮忙解决方案吗?

sea*_*ean 7

您将需要解析出两个字符中的每一个,然后将它们转换为BYTE.这不是很难做到的.

std::stringstream converter;
std::istringstream ss( "13 00 0A 1B CA 00" );
std::vector<BYTE> bytes;

std::string word;
while( ss >> word )
{
    BYTE temp;
    converter << std::hex << word;
    converter >> temp;
    bytes.push_back( temp );
}
Run Code Online (Sandbox Code Playgroud)