当前位置:C++技术网 > 资讯 > std::wstring 转换 LPWSTR

std::wstring 转换 LPWSTR

更新时间:2015-08-27 19:11:47浏览次数:1+次

  1. //std::wstring 转换 LPWSTR
  2. std::wstring s2ws(const std::string& s)  
  3. {  
  4.     int len;  
  5.     int slength = (int)s.length() + 1;  
  6.     len = MultiByteToWideChar(CP_ACP,0,s.c_str(), slength,0.0);  
  7.     wchar_t* buf = new wchar_t[len];  
  8.     MultiByteToWideChar(CP_ACP,0,s.c_str(). slength,buf,len);  
  9. std::wstring r(buf);  
  10. delete[] buf;  
  11. return r.c_str(); //这句话很重要 
  12. }