在eVC 4.0中将CString转换为char [英] Conversion of CString to char in eVC 4.0

查看:177
本文介绍了在eVC 4.0中将CString转换为char的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将CString数据转换为char [].有人告诉我该怎么做?

我的代码是这样的:

I want to convert a CString data into char[]. Some body tell me how to do this?

My code is like this :

CString strCamIP1 = _T("");
char g_acCameraip[16][17];
strCamIP1 = theApp.GetProfileString(strSection, _T("IP1"), NULL);
g_acCameraip[0] = strCamIP1;

推荐答案

您必须从TCHAR转换为char.

也许这堂课可以为您提供帮助:
http://cpansearch.perl.org/src/UNICOLET/Win32-TaskScheduler2.0.3/TConvert.h [ ^ ]

几年前,我在同一环境(eVC4,C/C ++)中使用了类似的东西
You have to convert from TCHAR to char.

Maybe this class can support you:
http://cpansearch.perl.org/src/UNICOLET/Win32-TaskScheduler2.0.3/TConvert.h[^]

Some years ago I used something similar in the same environment (eVC4, C/C++)


如果您不需要修改字符串,请使用:

http://www.codeproject.com/Articles/542/CString-Management#CString转换为char * I:转换为LPCTSTR

否则使用

http://www.codeproject.com/Articles/542/CString-Management#CString转换为char * II:使用GetBuffer
If you don''t need to modify string use:

http://www.codeproject.com/Articles/542/CString-Management#CString to char * I: Casting to LPCTSTR

else use

http://www.codeproject.com/Articles/542/CString-Management#CString to char * II: Using GetBuffer


TCHAR tchCamIPTemp[15];
	
_tcscpy(tchCamIPTemp, strCamIP1);
WideCharToMultiByte(CP_ACP, 0, tchCamIPTemp, -1, g_acCameraip[0], sizeof(g_acCameraip[0]), NULL, NULL);



首先,我将CString转换为TCHAR,然后借助WideCharToMultiByte方法将TCHAR数据转换为char.



First I convert the CString to TCHAR and then with the help of WideCharToMultiByte method convert the TCHAR data into char.


这篇关于在eVC 4.0中将CString转换为char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆