Click here to Skip to main content
14,937,188 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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;
Posted

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++)
   
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
   
v5
C++
TCHAR tchCamIPTemp[15];
	
_tcscpy(tchCamIPTemp, strCamIP1);
WideCharToMultiByte(CP_ACP, 0, tchCamIPTemp, -1, g_acCameraip[0], sizeof(g_acCameraip[0]), NULL, NULL);


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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900