std::ifstream file("data.bin", std::ios::binary);
vector<unsigned char> data((istreambuf_iterator<char>(file)),istreambuf_iterator<char>());
ofstream out("vector.txt");
for (int i = 0; i < data.size(); ++i)
{
out << "0x" << std::hex << setw(2) << setfill('0') << (int)data[i] << ",";
if ((i + 1) % 16 == 0)
{
out << std::endl;
}
}
out.close();
转换完成后效果如下,之后再转换成数组即可。