字符集转换: Ansi

    字符集转换: Ansi - Unicode

 1 wstring AnsiToUnicode (const string& strSrc )
 2 {
 3     /*!< 分配目标空间 */
 4     int iAllocSize = MultiByteToWideChar(CP_ACP,0,strSrc.c_str(),-1,NULL,NULL);
 5     WCHAR* pwszBuffer = new WCHAR[ (UINT)iAllocSize ];
 6     if ( NULL == pwszBuffer )
 7     {
 8         return L"";
 9     }    
10     int iCharsRet = MultiByteToWideChar( CP_ACP, 0, strSrc.c_str(),-1,pwszBuffer, iAllocSize );
11     /*!< 成功 */
12     wstring wstrRet;
13     if ( 0 < iCharsRet )
14     {
15         (void)wstrRet.assign ( pwszBuffer, static_cast<size_t>( iCharsRet ) );
16     }
17 
18     /*!< 释放内存 */
19     delete[] pwszBuffer;
20 
21     return wstrRet;
22 }
原文地址:https://www.cnblogs.com/hwm520hlf1314/p/3457009.html