#include <locale.h>
#include <Windows.h>
std::string WstringToString(const std::wstring str)
{
unsigned len = str.size() * 4;
setlocale(LC_CTYPE, "");
char *p = new char[len];
wcstombs(p,str.c_str(),len);
std::string str1(p);
delete[] p;
return str1;
}
std::wstring StringToWstring(string str)
{
std::wstring result;
int len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.size(), NULL, 0);
TCHAR* buffer = new TCHAR[len + 1];
MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.size(), buffer, len);
buffer[len] = '\0';
result.append(buffer);
delete[] buffer;
return result;
}
CString StringToCString(string str)
{
CString cs(str.c_str());
return cs;
}
Wstring和String、CString互转
最新推荐文章于 2024-01-18 10:20:55 发布