LPSTR/CString

How do I convert a CString to a LPSTR?
CString ctmp = "Hello";
LPSTR tmp = ctmp;
The above will not compile.
hotwheelsAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
inprasConnect With a Mentor Commented:
Hi
      CString str;
      str = "My String";
      LPSTR str1;
      strcpy(str1, str);

Hope this helps
0
 
MT_MUCommented:
CString ctmp = "Hello";
LPSTR tmp = (char *)(const char*)ctmp;
0
 
vachoohoCommented:
LPCTSTR is the "const char *"
LPSTR is the "char *"
fro ANSI builds
they are both fully interchangable
if you are not going to change the context (or going to if you want)

so no need to strcpy( ) it

just do casting

CString str = "string";
LPSTR lpstr = (LPSTR)(LPCTSTR)str;

will get the pointer to Cstring's buffer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.