std::string UTF8ToAnsi( const std::string& strIn, std::string& strOut )
![UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8 UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8](https://i-blog.csdnimg.cn/blog_migrate/2f88ce130b654eb5dc6788e02dbcfc90.gif)
![UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8 UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8](https://i-blog.csdnimg.cn/blog_migrate/a4c26d1e5885305701be709a3d33442f.gif)
{
WCHAR* strSrc = NULL;
TCHAR* szRes = NULL;
![UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8 UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
int i = MultiByteToWideChar(CP_UTF8, 0, strIn.c_str(), -1, NULL, 0);
![UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8 UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
strSrc = new WCHAR[i+1];
MultiByteToWideChar(CP_UTF8, 0, strIn.c_str(), -1, strSrc, i);
![UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8 UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
i = WideCharToMultiByte(CP_ACP, 0, strSrc, -1, NULL, 0, NULL, NULL);
![UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8 UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
szRes = new TCHAR[i+1];
WideCharToMultiByte(CP_ACP, 0, strSrc, -1, szRes, i, NULL, NULL);
![UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8 UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
strOut = szRes;
![UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8 UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
delete[] strSrc;
delete[] szRes;
![UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8 UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
return strOut;
}
![UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8 UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
std::string AnsiToUTF8( const std::string& strIn, std::string&
strOut )
![UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8 UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8](https://i-blog.csdnimg.cn/blog_migrate/2f88ce130b654eb5dc6788e02dbcfc90.gif)
![UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8 UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8](https://i-blog.csdnimg.cn/blog_migrate/a4c26d1e5885305701be709a3d33442f.gif)
{
WCHAR* strSrc = NULL;
TCHAR* szRes = NULL;
![UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8 UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
int len = MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)strIn.c_str(), -1, NULL,0);
![UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8 UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
unsigned short* wszUtf8 = new unsigned short[len+1];
memset(wszUtf8, 0, len * 2 + 2);
MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)strIn.c_str(), -1, (LPWSTR)wszUtf8, len);
![UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8 UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
len = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)wszUtf8, -1, NULL, 0, NULL, NULL);
![UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8 UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
char* szUtf8 = new char[len + 1];
memset(szUtf8, 0, len + 1);
WideCharToMultiByte (CP_UTF8, 0, (LPCWSTR)wszUtf8, -1, szUtf8, len, NULL,NULL);
![UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8 UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
strOut = szUtf8;
![UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8 UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
delete[] szUtf8;
delete[] wszUtf8;
![UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8 UTF8ToAnsi <wbr>和 <wbr>AnsiToUTF8](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
return strOut;