在 VC++ 開發中,如何將 ISO8859-1 編碼的字符串轉換為 Unicode(UTF-16)編碼?這是處理國際化文本時常見的需求。
Windows API 提供了 MultiByteToWideChar 函數可完成此轉換。ISO8859-1 的代碼頁為 28591。
#include
#include
std::wstring ISO88591ToUnicode(const std::string& str) {
if (str.empty()) return L"";
int len = MultiByteToWideChar(28591, 0, str.c_str(), -1, NULL, 0);
std::wstring wstr(len, 0);
MultiByteToWideChar(28591, 0, str.c_str(), -1, &wstr[0], len);
return wstr;
}
28591(ISO-8859-1)。std::wstring 即 Unicode 字符串。參考資源:CSDN 相關文章