windows下,string 转 LPCWSTR

来源:互联网 发布:linux vsftpd rpm下载 编辑:程序博客网 时间:2024/06/03 21:35

#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

原创粉丝点击