std::wstring StringToWString(std::string str){
int len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0);
wchar_t* wstr = new wchar_t[len+1];
memset(wstr, 0, len+1);
MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, wstr, len);
std::wstring ret(wstr);
if(wstr) delete[] wstr;
return ret;
}
std::string WStringToString(std::wstring wstr){
int len = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, NULL, 0, NULL, NULL);
char* str = new char[len+1];
memset(str, 0, len+1);
WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, str, len, NULL, NULL);
std::string ret(str);
if(str) delete[] str;
return ret;
}
#宽窄字符转换# C++如何实现wstring和string的互转
最新推荐文章于 2023-07-06 15:19:03 发布