C++中各种string 的相互转化 一 C++ 中 string 与 wstring 互转 方法一: string WideToMutilByte(const wstring& _src) { int nBufSize = WideCharToMultiByte(GetACP(), 0, _src
c_str(),-1, NULL, 0, 0, FALSE); char *szBuf = new char[nBufSize]; WideCharToMultiByte(GetACP(), 0, _src
c_str(),-1, szBuf, nBufSize, 0, FALSE); string strRet(szBuf); delete []szBuf; szBuf = NULL; return strRet; } wstring MutilByteToWide(const string& _src) { //计算字符串 string 转成 wchar_t 之后占用的内存字节数 int nBufSize = MultiByteToWideChar(GetACP(),0,_src
c_str(),-1,NULL,0); //为 wsbuf 分配内存 BufSize 个字节 wchar_t *wsBuf = new wchar_t[nBufSize]; //转化为 unicode 的 WideString MultiByteToWideChar(GetACP(),0,_src
c_str(),-1,wsBuf,nBufSize); wstring wstrRet(wsBuf); delete []wsBuf; wsBuf = NULL; return wstrRet; } 转载:csdn 这篇文章里,我将给出几种C++ std::string 和std::wstring 相互