Convert std::string to std::wstring or LPCWSTR

Convert std::string to std::wstring or LPCWSTR

转载
http://antoine-zhu.blogbus.com/logs/35979566.html


std::wstring s2ws(const std::string& s)
{
    
int len;
    
int slength = (int)s.length() + 1;
    len 
= MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 00);
    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;
}

std::wstring stemp 
= s2ws(myString);
LPCWSTR result 
= stemp.c_str();
posted @ 2009-07-08 20:36  ChenLu  阅读(1244)  评论(1编辑  收藏  举报