我有一个非常大的字符串,如下所示:
std::string tmpString = "0xC7,0x04,0x33,0xC0,0x49,0x74,0x0A,..."
我想将每个字符串化的字节转换回一个字节数组。 这种情况的最佳解决方案是什么?
我正在使用 VC++
最佳答案
试试这个:
std::string tmpString = "0xC7,0x04,0x33,0xC0,0x49,0x74,0x0A,...";
...
std::vector<BYTE> bytes;
bytes.reserve((tmpString.length() / 5) + 1);
std::istringstream iss(tmpString);
std::string s;
while (std::getline(iss, s, ',')) {
WORD num; // istreamstream does not have an '>>' operator for bytes
std::istringstream(s) >> std::hex >> num;
bytes.push_back(BYTE(num));
}
关于C++ 从字符串化字节转换字节数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22648711/