Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CString to array conversion? 1

Status
Not open for further replies.

ralphonzo

Programmer
Apr 9, 2003
228
GB
does any clever body out there have any idea how to convert a cstring to a character array? even being able to assign a pointer to the cstring would be nice. i've tried to assign a pointer with the #include <afx.h> which throws up no errors but breaks the computer (i presume there's a memory problem here but what do you do?).

it would seem sensible to use cstrings throughout the program but i'm in the process of converting a linear 'c' prog into a 'c++ mfc' job and there's tons of code to change in a short time for this to be possible.

can anybody help?

ralph
 
CString string;
string = &quot;blah blah blah&quot;;
LPCTSTR psz = string;

CString has an operator to convert to LPCTSTR. (LPCTSTR is the same thing as const TCHAR*)

If you need a non-const buffer, call GetBuffer on the string, and then ReleaseBuffer when you're done
 
thanks appaterno, i'm working on it. it takes a while for half-wits like me to get my head round some stuff,

ralph
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top