windows下,string 转 LPCWSTR

#ifdef UNICODE
std::wstring s2ws(const std::string& s)

{

 int len;

 int slength = (int)s.length() + 1;

 len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);

 wchar_t* buf = new wchar_t[len];

 MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);

 std::wstring r(buf);

 delete[] buf;

 return r;

}
#else
std::string s2ws(const std::string& s)
{
 return s;
}
#endif

你可能感兴趣的:(windows下,string 转 LPCWSTR)