How to Convert CString to Char*
-
Hi, Iam getting problem with converting CString into Char* and vise versa. If anyone helps me in this thanks for their help. Regards Pathi bhikshapathi_g@semanticspace.com
CString str("Some string"); char* chr = (char*)(const char*)str;
I vote pro drink :beer: -
Hi, Iam getting problem with converting CString into Char* and vise versa. If anyone helps me in this thanks for their help. Regards Pathi bhikshapathi_g@semanticspace.com
You can create a CString from a char*, and to go back do this CString s; s.GetBuffer(s.GetLength()+1); s.ReleaseBuffer(); Christian As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet. Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
-
CString str("Some string"); char* chr = (char*)(const char*)str;
I vote pro drink :beer:That will break if the contents of str are modified. GetBuffer() is the right way to get a non-const pointer to the string. --Mike-- http://home.inreach.com/mdunn/ Ford: How would you react if I said that I'm not from Guildford after all, but from a small planet somewhere in the vicinity of Betelguese? Arthur: I don't know. Why, do you think it's the sort of thing you're likely to say?
-
Hi, Iam getting problem with converting CString into Char* and vise versa. If anyone helps me in this thanks for their help. Regards Pathi bhikshapathi_g@semanticspace.com
Also, if you just need to pass a const char* to a CRT/WinAPI function, you can use CString s = "a string"; CallMyCharFunction((LPCTSTR)s); But if you really need a char* , use the methods above. CodeGuy The WTL newsgroup: 910 members and growing ... http://groups.yahoo.com/group/wtl
-
Hi, Iam getting problem with converting CString into Char* and vise versa. If anyone helps me in this thanks for their help. Regards Pathi bhikshapathi_g@semanticspace.com
strcpy(szstr, str.GetBuffer()); //where str is a CString and szstr is a char* Cheers!!! Carlos Antollini.