c++ gb2312 utf8 转换函数
来源:互联网 发布:贴吧发帖软件 编辑:程序博客网 时间:2024/06/03 11:18
这里两个函数实现GB2313与UTF8格式的互转,主要用于VC++在获取网页内容时解决乱码问题,因为VC++默认字符集是GB2312的,一般中文网站可能返回的是UTF-8编码,所以可以用U2G函数进行转换。
char* U2G(const char* utf8){ int len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0); wchar_t* wstr = new wchar_t[len+1]; memset(wstr, 0, len+1); MultiByteToWideChar(CP_UTF8, 0, utf8, -1, wstr, len); len = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL); char* str = new char[len+1]; memset(str, 0, len+1); WideCharToMultiByte(CP_ACP, 0, wstr, -1, str, len, NULL, NULL); if(wstr) delete[] wstr; return str;}//GB2312到UTF-8的转换char* G2U(const char* gb2312){ int len = MultiByteToWideChar(CP_ACP, 0, gb2312, -1, NULL, 0); wchar_t* wstr = new wchar_t[len+1]; memset(wstr, 0, len+1); MultiByteToWideChar(CP_ACP, 0, gb2312, -1, wstr, len); len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL); char* str = new char[len+1]; memset(str, 0, len+1); WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, NULL, NULL); if(wstr) delete[] wstr; return str;}
c++ gb2312 utf8 转换函数
阅读全文
1 0
- utf8-GB2312转换函数(c#)
- c++ gb2312 utf8 转换函数
- GB2312和 UTF8的互相转换函数
- Linux utf8与gb2312转换函数
- (c语言)gb2312和utf8转换
- UTF8 - GB2312转换
- UTF8、GB2312相互转换
- UTF8与GB2312之间转换的工具函数
- C+++Utf8字符转换Gb2312编码,解决TinyXml中文乱码
- 从UTF8格式向GB2312格式转换[C源码](转)
- url 编码转换(utf8 - gb2312)
- url 编码转换(utf8 - gb2312)
- UTF8 到GB2312 的 转换
- GB2312和utf8编码转换
- js 编码转换 gb2312 & utf8
- C++ UTF8 编码转换 GB2312
- utf8 和 gb2312 的转换
- GB2312与UTF8相互转换
- 高效的浏览 Linux 目录结构:pushd和popd命令
- 让我进去--实验吧
- 动态表单设计
- 首字母转换大小写以及实体类是否存在某个方法名
- 线程池的探索
- c++ gb2312 utf8 转换函数
- 单词记忆
- hdu 2222Keywords Search(AC自动机入门好题)
- Yii2权限管理之ACF
- LightOJ 1341 Aladdin and the Flying Carpet
- 多线程编程
- ajax
- 找出动词前面的并以动词命名
- 【Python版】OpenCV学习笔记(1):安装