Wstring转换为String类型

来源:互联网 发布:淘宝年货节是什么时候 编辑:程序博客网 时间:2024/05/08 02:06

std::string ws2s(const std::wstring& ws)
 {
  string curLocale = setlocale(LC_ALL, NULL); // curLocale = "C";
  setlocale(LC_ALL, "chs");
  const wchar_t* _Source = ws.c_str();
  size_t _Dsize = 2 * ws.size() + 1;
  char *_Dest = new char[_Dsize];
  memset(_Dest,0,_Dsize);
  wcstombs(_Dest,_Source,_Dsize);
  std::string result = _Dest;
  delete []_Dest;
  setlocale(LC_ALL, curLocale.c_str());
  return result;
 }

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/li_guotao/archive/2008/04/20/2308260.aspx

原创粉丝点击