首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

UTF-8 转 GB2312,该如何解决

2012-04-26 
UTF-8 转 GB2312各位高手,谁有UTF-8转gb2312 的示例代码,我从网上找了一些资料,然后用OUTLOOK 发送邮件,自

UTF-8 转 GB2312
各位高手,谁有UTF-8转gb2312 的示例代码,我从网上找了一些资料,然后用OUTLOOK 发送邮件,自己这边的服务器接受,然后解析,发现还是不行 .谁有代码能分享一下吗.高份相送

[解决办法]

C/C++ code
qp::StringW Global::AnsiToUnicode(const char* buf){    int len = ::MultiByteToWideChar(CP_ACP, 0, buf, -1, NULL, 0);    if (len == 0) return L"";    std::vector<wchar_t> unicode(len);    ::MultiByteToWideChar(CP_ACP, 0, buf, -1, &unicode[0], len);    return &unicode[0];}qp::StringA Global::UnicodeToAnsi(const wchar_t* buf){    int len = ::WideCharToMultiByte(CP_ACP, 0, buf, -1, NULL, 0, NULL, NULL);    if (len == 0) return "";    std::vector<char> utf8(len);    ::WideCharToMultiByte(CP_ACP, 0, buf, -1, &utf8[0], len, NULL, NULL);    return &utf8[0];}qp::StringW Global::Utf8ToUnicode(const char* buf){    int len = ::MultiByteToWideChar(CP_UTF8, 0, buf, -1, NULL, 0);    if (len == 0) return L"";    std::vector<wchar_t> unicode(len);    ::MultiByteToWideChar(CP_UTF8, 0, buf, -1, &unicode[0], len);    return &unicode[0];}qp::StringA Global::UnicodeToUtf8(const wchar_t* buf){    int len = ::WideCharToMultiByte(CP_UTF8, 0, buf, -1, NULL, 0, NULL, NULL);    if (len == 0) return "";    std::vector<char> utf8(len);    ::WideCharToMultiByte(CP_UTF8, 0, buf, -1, &utf8[0], len, NULL, NULL);    return &utf8[0];}
[解决办法]
原理
http://www.diybl.com/course/3_program/c++/cppsl/2008227/101920.html

http://blog.csdn.net/yaoohfox/archive/2009/04/20/4093638.aspx

API

[解决办法]
1楼写的很全了,组合在一起就行了。
[解决办法]
GBK、GB2312等与UTF8之间都必须通过Unicode编码才能相互转换:
GBK、GB2312--Unicode--UTF8
UTF8--Unicode--GBK、GB2312
[解决办法]
先Base64解码一次。解码后的格式为Utf-8

=?UTF-8?B?5Zu95a62?=中的?B?应该指的是base64

热点排行
Bad Request.