std::string bytes2string(const char* bytes, const int length) { std::stringstream ss; ss << "\n"; for (int i = 0; i < length; ++i) { ss << std::hex << std::setw(2) << std::setfill('0') << (unsigned int)(*(bytes + i)& 0xff) << " "; if ((i+1) % 16 == 0) { ss << "\n"; } } ss << "\n"; return ss.str(); }
輸出效果: