64,637
社区成员
发帖
与我相关
我的任务
分享
std::wstring ansi2unicode(const std::string& ansi)
{
if (ansi.empty()) {
return std::wstring(L"");
}
int len = MultiByteToWideChar(CP_ACP, 0, ansi.c_str(), -1, NULL, 0);
std::wstring unicode(len + 2, L'\0');
len = MultiByteToWideChar(CP_ACP, 0, ansi.c_str(), ansi.size(), &unicode[0], len);
return unicode;
}
std::string unicode2ansi(const std::wstring& unicode)
{
if (unicode.empty()) {
return std::string("");
}
int len = WideCharToMultiByte(CP_ACP, 0, unicode.c_str(), -1, NULL, 0, NULL, NULL);
std::string ansi(len + 1, '\0');
WideCharToMultiByte(CP_ACP, 0, unicode.c_str(), unicode.size(), &ansi[0], len, NULL, NULL);
return ansi;
}