Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
plz help me ....

hello dear solved error

error C2440: '<function-style-cast>' : cannot convert from 'CString' to 'LPCSTR'

my code:
C++
char * pchData;
strcpy(pchData, LPCSTR(strData));
Posted
Updated 28-Jun-13 10:04am
v2

You might use the CT2A macro, see ATL and MFC String Conversion Macros[^] (please, read carefully the documentation).
 
Share this answer
 
You cannot copy a CString to a string pointer. From the rror message you got, I assume that strData is of type CString. If for whatever reason you need a pointer to a nul-terminated string you can ask the CString object to give you such a pointer by simply writing
C++
const char* pchData = strData;

Not however that this pointer is only good as long the CString object lives.
 
Share this answer
 
Comments
inlandchris1 21-May-21 3:57am    
To get data out of a CString = (char *)strData.GetString();

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