How do I convert from a CString to a character array.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
ie:
char* string1;
CString string2("Hello");
/*
How would I go about putting Hello
into string1?
*/
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Thanks,
Phil
Printable View
How do I convert from a CString to a character array.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
ie:
char* string1;
CString string2("Hello");
/*
How would I go about putting Hello
into string1?
*/
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Thanks,
Phil
Try this...
char* string1;
CString string2("Hello");
string1 = string2.GetBuffer(-1);
char* string1;
CString string2("Hello");
// Try this...
string1 = new char[string2.GetLength()];
strcpy(string1,(LPCTSTR)string2);
this should work....
nms
char* s1;
CString s2 ("Hello");
s1 = (char*)(const char*)s2;
// This will xfer the contents of s2 to s1
Cheers!
Chandra
I'd prefer this one:
char* string1 = NULL;
CString string2("Hello");
// Try this...
string1 = new char[string2.GetLength() + 1];
::strcpy(string1, string2);
Sally
Nope it won't. it will make s1 POINT to s2 which is different
Sally