GBK转UTF8 C++实现代码
2014-12-25 16:27
423 查看
string GBKToUTF8(const std::string& strGBK, int& nLen)
{
string strOutUTF8 = "";
WCHAR * str1;
int n = MultiByteToWideChar(CP_ACP, 0, strGBK.c_str(), -1, NULL, 0);
str1 = new WCHAR
;
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
;
nLen = WideCharToMultiByte(CP_UTF8, 0, str1, -1, str2, n, NULL, NULL);
strOutUTF8 = str2;
delete[]str1;
str1 = NULL;
delete[]str2;
str2 = NULL;
return strOutUTF8;
}
{
string strOutUTF8 = "";
WCHAR * str1;
int n = MultiByteToWideChar(CP_ACP, 0, strGBK.c_str(), -1, NULL, 0);
str1 = new WCHAR
;
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
;
nLen = WideCharToMultiByte(CP_UTF8, 0, str1, -1, str2, n, NULL, NULL);
strOutUTF8 = str2;
delete[]str1;
str1 = NULL;
delete[]str2;
str2 = NULL;
return strOutUTF8;
}
相关文章推荐
- Android NDK的C/C++代码中利用JNI回调实现字符编码转换的试验(中文UTF8与GBK)
- Android NDK的C/C++代码中利用JNI回调实现字符编码转换的试验(中文UTF8与GBK)
- Android NDK的C/C++代码中利用JNI回调实现字符编码转换的试验(中文UTF8与GBK)
- Java实现的utf8,gbk,unicode编码相互转换的代码
- Java实现的utf8,gbk,unicode编码相互转换的代码
- Java实现的utf8,gbk,unicode编码相互转换的代码
- C++实现判断一个字符串是否为UTF8或GBK格式的方法
- PHP写入WRITE编码为UTF8的文件的实现代码
- 单链表的C++代码实现
- 用C/C++实现代码的动态修改(SMC)
- Singleton模式的C++实现研究(示例代码)
- 跨平台的UTF8GBK转换以及GBKw_chart转换代码,支持std::string
- 键树的c++代码实现
- 用C/C++实现代码的动态修改(SMC)
- C++ + WMI + DDK 实现获得显卡信息 代码
- VC 实现 汉字 GBK(GB2312) 转化为 UTF8 编码
- 程序员面试题精选(48):两个堆栈模拟队列c++代码实现
- 跨平台的UTF8GBK转换以及GBKw_chart转换代码,支持std::string
- Mysql以utf8存储gbk输出的实现方法提供
- Singleton模式的C++实现研究(示例代码)