// 宽字符转UTF8
string EncodeUtf8(wstring in)
{
string s(in.length()*3+1,‘ ‘);
size_t len = ::WideCharToMultiByte(CP_UTF8, 0, in.c_str(), in.length(), &s[0], s.length(), NULL, NULL);
s.resize(len);
return s;
}
// UTF8 转宽字符
wstring DecodeUtf8(string in)
{
wstring s(in.length(), _T(‘ ‘));
size_t len = ::MultiByteToWideChar(CP_UTF8, 0, in.c_str(), in.length(), &s[0], s.length());
s.resize(len);
return s;
}
原文地址:http://blog.csdn.net/wanglei9876/article/details/43772991