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;

You have to convert from TCHAR to char.

Maybe this class can support you:[^]

Some years ago I used something similar in the same environment (eVC4, C/C++)
If you don't need to modify string use: to char * I: Casting to LPCTSTR

else use 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);

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