//将std::string转成std::wstring
std::wstring DeltaRecorder::MultibyteToWide(const std::string& multibyte)
{
size_t length = multibyte.length();
if (length == 0)
return std::wstring();
wchar_t * wide = new wchar_t[multibyte.length()*2+2];
if (wide == NULL)
return std::wstring();
int ret = MultiByteToWideChar(CP_ACP, 0, multibyte.c_str(), (int)multibyte.size(), wide, (int)length*2 - 1);
wide[ret] = 0;
std::wstring str = wide;
delete[] wide;
return str;
std::string DeltaRecorder::ws2s(const std::wstring& ws)
{
string curLocale = setlocale(LC_ALL, NULL); // curLocale = "C";
setlocale(LC_ALL, "chs");
const wchar_t* _Source = ws.c_str();
size_t _Dsize = 2 * ws.size() + 1;
char *_Dest = new char[_Dsize];
memset(_Dest,0,_Dsize);
wcstombs(_Dest,_Source,_Dsize);
string result = _Dest;
delete []_Dest;
setlocale(LC_ALL, curLocale.c_str());
return result;
}
std::wstring DeltaRecorder::MultibyteToWide(const std::string& multibyte)
{
size_t length = multibyte.length();
if (length == 0)
return std::wstring();
wchar_t * wide = new wchar_t[multibyte.length()*2+2];
if (wide == NULL)
return std::wstring();
int ret = MultiByteToWideChar(CP_ACP, 0, multibyte.c_str(), (int)multibyte.size(), wide, (int)length*2 - 1);
wide[ret] = 0;
std::wstring str = wide;
delete[] wide;
return str;
}
std::string DeltaRecorder::ws2s(const std::wstring& ws)
{
string curLocale = setlocale(LC_ALL, NULL); // curLocale = "C";
setlocale(LC_ALL, "chs");
const wchar_t* _Source = ws.c_str();
size_t _Dsize = 2 * ws.size() + 1;
char *_Dest = new char[_Dsize];
memset(_Dest,0,_Dsize);
wcstombs(_Dest,_Source,_Dsize);
string result = _Dest;
delete []_Dest;
setlocale(LC_ALL, curLocale.c_str());
return result;
}