//将中英文字符串或者英文+中文乱码转换为十六进制
string ErrString = “unknown error; 未知错误”;
const char *str = ErrString.data();
for (int i = 0; i < strlen(str); i++)
{
printf("0x%02x, ", *(char *)(str+(long)i));
}
//将异常中的乱码转为正常的中文
int nwLen = MultiByteToWideChar(CP_UTF8, 0, ErrString.c_str(), -1, NULL, 0);//算出合适的长度
LPWSTR strUnicode = new WCHAR[nwLen];
MultiByteToWideChar(CP_UTF8, 0, ErrString.c_str(), -1, strUnicode, nwLen);//ASCII转UNICODE
int nLen = WideCharToMultiByte(CP_ACP, 0, strUnicode, -1, NULL, 0, "", false);//算出合适的长度
char *strAscii = new char[nLen];
WideCharToMultiByte(CP_ACP, 0, strUnicode, -1, strAscii, nLen, "", false);//UNICODE转ASCII
cout << "GetErrString返回的是:" << strAscii << endl;
delete []strUnicode;
delete []strAscii;