c++国标与UTF_8的转换
来源:互联网 发布:java前后端分离是什么 编辑:程序博客网 时间:2024/06/04 18:50
转自http://blog.csdn.net/p569354158/article/details/6567175
#include <iostream> #include <string> #include <fstream> #include <windows.h> using namespace std; string GBKToUTF8(const std::string& strGBK) { string strOutUTF8 = ""; WCHAR * str1; int n = MultiByteToWideChar(CP_ACP, 0, strGBK.c_str(), -1, NULL, 0); str1 = new WCHAR[n]; MultiByteToWideChar(CP_ACP, 0, strGBK.c_str(), -1, str1, n); n = WideCharToMultiByte(CP_UTF8, 0, str1, -1, NULL, 0, NULL, NULL); char * str2 = new char[n]; WideCharToMultiByte(CP_UTF8, 0, str1, -1, str2, n, NULL, NULL); strOutUTF8 = str2; delete[]str1; str1 = NULL; delete[]str2; str2 = NULL; return strOutUTF8; } string UTF8ToGBK(const std::string& strUTF8) { int len = MultiByteToWideChar(CP_UTF8, 0, strUTF8.c_str(), -1, NULL, 0); unsigned short * wszGBK = new unsigned short[len + 1]; memset(wszGBK, 0, len * 2 + 2); MultiByteToWideChar(CP_UTF8, 0, (LPCTSTR)strUTF8.c_str(), -1, wszGBK, len); len = WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, NULL, 0, NULL, NULL); char *szGBK = new char[len + 1]; memset(szGBK, 0, len + 1); WideCharToMultiByte(CP_ACP,0, wszGBK, -1, szGBK, len, NULL, NULL); //strUTF8 = szGBK; std::string strTemp(szGBK); delete[]szGBK; delete[]wszGBK; return strTemp; } int _tmain(int argc, _TCHAR* argv[]) { string test("我们中国是个强大的名族,强大的动力来自每个人的支持"); fstream output("test.txt",ios_base::out | ios_base::app); output << GBKToUTF8(test); //system("iconv -f GBK -t utf-8"); return 0; }
- c++国标与UTF_8的转换
- utf_8与GB2312编码的转换
- 字符串与UTF_8的相互转换
- UTF_8 与 ASCII之间的转换
- C++ Unicode与UTF_8 编码转换
- gbk转换到utf_8
- UTF_8与GB2312互转
- 区位码,国标码,内码之间的区别与联系,以及如何转换
- 汉字编码与编程相关问题总结:ASCII、机内码、区位码、国标码、Unicode码是如何转换的
- 汉字编码与编程相关问题总结:ASCII、机内码、区位码、国标码、Unicode码是如何转换的
- GB2312、UTF_8、UNICODE之间相互转换
- 从程序员的观点看 汉字国标与Unicode
- 用C语言(apue)实现 把时间戳转换为国标格式的字符串(2013-09-03 15:36:12)的函数
- 国标2312转换UCS2码
- jsp编码UTF_8的不可映射问题
- 汉字编码与编程相关问题总结:ASCII、机内码、区位码、国标码、Unicode码他们之间是如何转换的
- 国标码与区位码
- Wince下GB(国标字符)和Unicode的相互转换方法
- 二分检索(汇编)
- Cgroup用法解析
- Java白盒测试工具
- Ant介绍及应用
- sqrt函数实现
- c++国标与UTF_8的转换
- 整数数组,长度为n,分为m份。求m最大值
- Unix NetWork Programming——环境搭建(解决unp.h等源码编译问题)
- hadoop http address绑定内网地址
- 不能跳过的《程序员的职业素养(The Clean Coder)》中的一个章节
- 方法 REG_EXTRACT
- 用C api 连接mysql数据库的 开发实例
- Hi3511的G726音频如何解?
- 为什么《七周七语言》选中的是这几种语言?