GBK转utf-8,宽字符转窄字符
//GBK转UTF8
string CAppString::GBKToUTF8(const 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;
} //UTF8转GBK
string CAppString::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, (LPCSTR)strUTF8.c_str(), -1, (LPWSTR)wszGBK, len); len = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)wszGBK, -1, NULL, 0, NULL, NULL);
char *szGBK = new char[len + 1];
memset(szGBK, 0, len + 1);
WideCharToMultiByte(CP_ACP,0, (LPWSTR)wszGBK, -1, szGBK, len, NULL, NULL);
//strUTF8 = szGBK;
std::string strTemp(szGBK);
delete[]szGBK;
delete[]wszGBK;
return strTemp;
} //宽字符转窄
string CAppString::Unicode2ACSII(const wstring & strSource)
{
string strDest("");
if (strSource.empty())
{
return strDest;
} int nlen = ::WideCharToMultiByte(CP_ACP, 0, strSource.c_str(), -1, NULL, 0, NULL, NULL);
char * szDest = new char[nlen + 1];
::WideCharToMultiByte(CP_ACP, 0, strSource.c_str(), -1, szDest, nlen, NULL, NULL);
strDest = szDest;
delete szDest;
szDest = NULL; return strDest;
} //窄字符转宽字符
wstring CAppString::ASCII2Unicode(const char* strSrc)
{
wchar_t* pElementText = NULL;
int nTextLen = 0;
// multi char to wide char
nTextLen = MultiByteToWideChar( CP_ACP, 0, strSrc, -1, NULL, 0 );
pElementText = new wchar_t[nTextLen + 1];
memset(( void* )pElementText, 0, sizeof( wchar_t ) * ( nTextLen + 1 ) );
::MultiByteToWideChar(CP_ACP, 0, strSrc, -1, pElementText, nTextLen);
wstring sText;
sText = pElementText;
delete[] pElementText;
return sText;
}
GBK转utf-8,宽字符转窄字符的更多相关文章
- 宽字符转窄字符CW2AEX<>(szAreaInfo,CP_UTF8)
CString szAreaInfo; CW2AEX<>(szAreaInfo,CP_UTF8); 最好能像上面这样转换,否则汉字就会转成乱码.
- 宽字符wchar_t和窄字符char——putwchar、wprintf
宽字符wchar_t 与 窄字符char 先说下窄字符char,这个大部分读者应该很清楚,char类型的变量占一个字节(byte)(也就是8个bit(比特)),能表示256个字符,那char的范围有两 ...
- C++ 宽字符(wchar_t)与窄字符(char)的转换
了解 长度 宽字符wchar_t的长度16位,可以用来显示中文等除英文外的其他文字, 窄字符 char 的长度 8 位,只能处理英文. 哪里可以见到 在VS2010, 2012, 2013 ...
- volatile,可变参数,memset,内联函数,宽字符窄字符,国际化,条件编译,预处理命令,define中##和#的区别,文件缓冲,位域
1.volatile: 要求参数修改每次都从内存中的读取.这种情况要比普通运行的变量需要的时间长. 当设置了成按照C99标准运行之后,使用volatile变量之后的程序运行的时间将比register的 ...
- C语言小程序——推箱子(窄字符和宽字符)
C语言小程序——推箱子(窄字符Version) 推箱子.c #include <stdio.h> #include <conio.h> #include <stdlib. ...
- 宽字符wchar_t和窄字符char区别和相互转换
转自:http://blog.csdn.net/nodeathphoenix/article/details/7416725 1. 首先,说下窄字符char了,大家都很清楚,就是8bit表示的b ...
- 关于MultiByteToWideChar与WideCharToMultiByte代码测试(宽字符与多字节字符的转换)以及字符串的转换代码测试
#pragma once #include <stdio.h> //getchar() #include <tchar.h> #include <stdlib.h> ...
- Spark --【宽依赖和窄依赖】
前言 Spark中RDD的高效与DAG图有着莫大的关系,在DAG调度中需要对计算过程划分stage,暴力的理解就是stage的划分是按照有没有涉及到shuffle来划分的,没涉及的shuffle的都划 ...
- Spark 中的宽依赖和窄依赖
Spark中RDD的高效与DAG图有着莫大的关系,在DAG调度中需要对计算过程划分stage,而划分依据就是RDD之间的依赖关系.针对不同的转换函数,RDD之间的依赖关系分类窄依赖(narrow de ...
随机推荐
- poj 3259 (Bellman_Ford判断负环)
题意:John的农场里n块地,m条路连接两块地,k个虫洞,虫洞是一条单向路,不但会把你传送到目的地,而且时间会倒退Ts.我们的任务是知道会不会在从某块地出发后又回来,看到了离开之前的自己. 思路:虫洞 ...
- Cocos2d-x CCNotificationCenter 通知中心
相信接触过ios开发的人来说对NSNotificationCenter都不陌生.而在cocos2d-x中也参照这个类,提供了CCNotificationCenter这个类,用作通知中心. 那么Noti ...
- poj1547---结构数组
题意:老师发给每个学生的橡皮泥相同,找出谁抢了谁的橡皮泥 思路:结构数组存储每个学生的橡皮总量,和名字 /* 结构数组存储用户信息--只放名称和体积 while输入循环复用长宽高变量 for循环求所有 ...
- linux 磁盘空间扩容 vg(+pv) lv(+空间) lv(缩减磁盘空间)
preFace APP scenario description: 当你未能合理的规划存储时,在后期的维护工作中可能会涉及的存储的 再规划(eg,某一个 or 数个App 对某一个lv 即挂载点写Bi ...
- mongodb查询关于大于小于的用法;
mongoDB查询操作符: http://www.runoob.com/mongodb/mongodb-operators.html 项目中需要的场景是这样的,每个人每天只能领取一张明信片,换句话说, ...
- C#反射动态赋值
很多时候我们需要在数据实体层读取数据后赋值到领域模型时往往会产生如下的代码 public class A { public string Name {get;set;} public int Age ...
- .net 资源
基于.net构架的留言板项目大全源码 http://down.51cto.com/zt/70 ASP.net和C#.net通用权限系统组件功能教程 http://down.51cto.com/zt/1 ...
- C++ Member Functions的各种调用方式
[1]Nonstatic Member Functions(非静态成员函数) C++的设计准则之一就是:nonstatic member function至少必须和一般的nonmember funct ...
- 如何让对象只在堆或者栈中分配空间ANDC++禁止一个类被继承
在开始之前先来分析一下C++中的new运算符和operator new之间的关联. new:指我们在C++里通常用到的运算符,比如A* a = new A或者调用带参数的构造函数; 对于new来说, ...
- PHP图片裁剪函数(图像不变形)
PHP图片裁剪函数(图像不变形) <? *exif_imagetype -- 判断一个图像的类型 *说明:函数功能是把一个图像裁剪为任意大小的图像,图像不变形 * 参数说明:输入 需要处理图片的 ...