C++中文乱码转为十六进制和转为正常中文 |
您所在的位置:网站首页 › 16进制转换文字乱码 › C++中文乱码转为十六进制和转为正常中文 |
//将中英文字符串或者英文+中文乱码转换为十六进制 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 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |