{
return MBCS2CString(stdStr.c_str());
}
#include<string>
using namespace std;
//將string轉(zhuǎn)換成wstring
wstring string2wstring(string str)
{
wstring result;
//獲取緩沖區(qū)大小,并申請(qǐng)空間,緩沖區(qū)大小按字符計(jì)算
int len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.size(), NULL, 0);
TCHAR* buffer = new TCHAR[len + 1];
//多字節(jié)編碼轉(zhuǎn)換成寬字節(jié)編碼
MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.size(), buffer, len);
buffer[len] = '\0'; //添加字符串結(jié)尾
//刪除緩沖區(qū)并返回值
result.append(buffer);
delete[] buffer;
return result;
}
//將wstring轉(zhuǎn)換成string
string wstring2string(wstring wstr)
{
string result;
//獲取緩沖區(qū)大小,并申請(qǐng)空間,緩沖區(qū)大小事按字節(jié)計(jì)算的
int len = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), wstr.size(), NULL, 0, NULL, NULL);
char* buffer = new char[len + 1];
//寬字節(jié)編碼轉(zhuǎn)換成多字節(jié)編碼
WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), wstr.size(), buffer, len, NULL, NULL);
buffer[len] = '\0';
//刪除緩沖區(qū)并返回值
result.append(buffer);
delete[] buffer;
return result;
}