|
-
May 8th, 1999, 05:24 PM
#1
Converting CStrings to char*
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
-
May 8th, 1999, 07:12 PM
#2
Re: Converting CStrings to char*
Try this...
char* string1;
CString string2("Hello");
string1 = string2.GetBuffer(-1);
-
May 10th, 1999, 12:44 PM
#3
Re: Converting CStrings to char*
char* string1;
CString string2("Hello");
// Try this...
string1 = new char[string2.GetLength()];
strcpy(string1,(LPCTSTR)string2);
this should work....
nms
-
May 10th, 1999, 04:17 PM
#4
Re: Converting CStrings to char*
char* s1;
CString s2 ("Hello");
s1 = (char*)(const char*)s2;
// This will xfer the contents of s2 to s1
Cheers!
Chandra
-
May 10th, 1999, 08:16 PM
#5
Re: Converting CStrings to char*
I'd prefer this one:
char* string1 = NULL;
CString string2("Hello");
// Try this...
string1 = new char[string2.GetLength() + 1];
::strcpy(string1, string2);
Sally
-
May 10th, 1999, 08:17 PM
#6
Re: Converting CStrings to char*
Nope it won't. it will make s1 POINT to s2 which is different
Sally
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|