zoukankan
html css js c++ java
WCHAR* CHAR* 转换
//包含头文件
#include <AFXCONV.H>
CString strUnicode(_T( "unicode string "));
USES_CONVERSION;
char* pszChar = W2A(strUnicode));
MultiByteToWideChar
WideCharToMultiByte
void
ConvertUtf8ToGBK(CString
&
strUtf8)
{
int
len
=
MultiByteToWideChar(CP_UTF8,
0
, (LPCTSTR)strUtf8,
-
1
, NULL,
0
);
unsigned
short
*
wszGBK
=
new
unsigned
short
[len
+
1
];
memset(wszGBK,
0
, len
*
2
+
2
);
MultiByteToWideChar(CP_UTF8,
0
, (LPCTSTR)strUtf8,
-
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;
delete[] szGBK;
delete[] wszGBK;
}
void
ConvertGBKToUtf8(CString
&
strGBK)
{
int
len
=
MultiByteToWideChar(CP_ACP,
0
, (LPCTSTR)strGBK,
-
1
, NULL,
0
);
unsigned
short
*
wszUtf8
=
new
unsigned
short
[len
+
1
];
memset(wszUtf8,
0
, len
*
2
+
2
);
MultiByteToWideChar(CP_ACP,
0
, (LPCTSTR)strGBK,
-
1
, wszUtf8, len);
len
=
WideCharToMultiByte(CP_UTF8,
0
, wszUtf8,
-
1
, NULL,
0
, NULL, NULL);
char
*
szUtf8
=
new
char
[len
+
1
];
memset(szUtf8,
0
, len
+
1
);
WideCharToMultiByte (CP_UTF8,
0
, wszUtf8,
-
1
, szUtf8, len, NULL,NULL);
strGBK
=
szUtf8;
delete[] szUtf8;
delete[] wszUtf8;
}
查看全文
相关阅读:
PYTHON压平嵌套列表
linux下IPTABLES配置详解
Python面试必须要看的15个问题
两个实用的Python的装饰器
Python的16个“坑”
python实现不可修改的常量
51nod-1322: 关于树的函数
51nod-1310: Chandrima and XOR
51nod-1296: 有限制的排列
51nod-1277: 字符串中的最大值
原文地址:https://www.cnblogs.com/abinxm/p/2196862.html
最新文章
mysql的安装与配置
[HNOI2008]遥远的行星
[COGS 347]地震
[luogu 3369]普通平衡树(fhq_treap)
[HDU 1075]What Are You Talking About
[HDU 4417]Super Mario
[HNOI2011]括号修复
[NOIP2017]宝藏
[HAOI2010]订货
[luogu 1660]数位平方和
热门文章
[CQOI2014]排序机械臂
[HNOI2013]消毒
[HNOI2014]米特运输
[SDOI2010]粟粟的书架
[SDOI2014]旅行
[HNOI2012]集合选数
Python中list的实现
Use weakref module in a cache or mapping
python中基于descriptor的一些概念
WebSocket with Flask
Copyright © 2011-2022 走看看