- 8
- 0
- 约7.7千字
- 约 13页
- 2017-06-05 发布于河南
- 举报
Cstring转char、string、int等数据类型的方法(国外英文资料)
Cstring转char、string、int等数据类型的方法
Unicode the CString is converted to char *
Method one: use the API: WideCharToMultiByte for conversion
CString STR = _T ( D: \ the school project \ \ qq.bmp );
/ / note: the following n and len values are different, n is calculated by character, and len is calculated by bytes
Int n = STR. GetLength (); / / n = 14, len = 18
/ / to get the size of the wide byte character, the size is calculated by bytes
Int len = WideCharToMultiByte (CP_ACP, 0, STR, STR. GetLength (), NULL, 0, NULL);
/ / for the multi-byte character array application space, the size of the array is the size of the byte bytes in bytes
Char * pFileName = new char [len + 1]; / / in bytes
/ / wide byte encoding translates into multi-byte encoding
WideCharToMultiByte (CP_ACP, 0, STR, STR. GetLength (), pFileName, len, NULL);
PFileName [len + 1] = \ 0; / / multi-byte characters end with \ 0
Method 2: use functions: T2A, W2A
CString STR = _T ( D: \ the school project \ \ qq.bmp );
/ / declare identifier
USES_CONVERSION;
/ / call functions, T2A and W2A both support character conversion in both ATL and MFC
Char * pFileName = T2A (STR);
/ / char * pFileName = W2A (STR); / / the transformation can also be implemented
Note: you may also need to add reference # include afxpriv.h
Unicode below char * converts to CString
Method one: use the API: MultiByteToWideChar for conversion
A char * pFileName = D: \ the school project \ \ QQ.
/ / compute the char * array size, in bytes, and a Chinese character in two bytes
Int charLen = strlen (pFileName);
/ / calculate the size of multi-byte characters by character.
Int len = MultiByteToWideChar (CP_ACP, 0, pFileName, charLen, NULL, 0);
/ / for a wide byte character array application space, the array size is the size of multi-byte characters calculated in bytes
TCHAR buf = new TCHAR [len + 1];
/ / multi-byte encoding translates into wide byte encoding
MultiByteToWideChar (CP_ACP, 0, pFileName, charLen, buf, len);
Buf [len] = \ 0; / / to add t
您可能关注的文档
最近下载
- 明代宗教信仰与思想控制.docx VIP
- 江苏省南通市2024-2025学年高二上学期期末学业质量监测语文试卷(含答案).pdf VIP
- 国就有成人演出的电影了?想看就要冒生命危险.pdf VIP
- 综合素质练习题及答案.doc VIP
- 2020-2021学年北京高三化学二轮复习 反应原理型简答题(突破二卷)(word版 含答案).docx VIP
- 电力拖动控制线路安装与检修(白银矿冶职业技术学院)知到智慧树答案.docx VIP
- 煤炭巷道掘砌工(高级工)资格考试题库(全真题库).docx VIP
- 影像叙事中情感共鸣生成机制.docx VIP
- 同轴二级圆柱齿轮减速器的设计(硬齿面).doc VIP
- 基于GPU多线程多通道图像高速重构方法、设备及介质.pdf VIP
原创力文档

文档评论(0)