Message Board


Message Board > C/C++ > CString to char* in VC++ ???

November 7, 2006, 16:35
Quiest
now with more happynes
142 posts

How do I convert a CString to char?

strcpy(char_var, CString_var); isnt working.

I tried

char_var = (char*)CString_var.GetString();

which is partly working but it seems to copy a lot of other stuff (conversion symbols/tags?) too.
The char_var displays correctly in a MessageBox, but
I can`t get a char with char_var[3] for example out of it.

char_var=CString_var.GetAt(3); isnt working either, as well as .GetBuffer...

[Edited on November 7, 2006 by Quiest]
____________
Roundhousekick to the face, baby!
#
November 7, 2006, 20:13
PEader
お前はもう死んでいる
1486 posts

Do you mean the MFC CSTring class? Look at the getBuffer member variable. IS MFC not dead?

The reason for it copying lots of other stuff might be because it is either unicode or wchar format. Why do you want to take it out of the CString and put it into a char array?
____________
I see 57,005 people.
#
November 7, 2006, 23:43
Quiest
now with more happynes
142 posts

Doing this for work...

The fields I`m using to enter a date (dd.mm.yyyy) only give me the option to read the entered text as CString.

I have to convert it into a char array, cause the function I had to write needs it like that (converts it to ints then, I know its stupid, but it has to be that way).

Maybe someone can tell me, if I can change the those fields somehow so they read it as string or char[] directly?
____________
Roundhousekick to the face, baby!
#
November 8, 2006, 11:51
PEader
お前はもう死んでいる
1486 posts

Did you read the MSDN library entry for the CString class? That tells you how to convert it to a const char pointer and how to access the array directly.
Read about the http://msdn.microsoft.com/libr … PCTSTR operator.
Code:
//data == CString
(LPCTSTR)data );


[Edited on November 8, 2006 by PEader]
____________
I see 57,005 people.
#

Message Board > C/C++ > CString to char* in VC++ ???

Quick reply


You must log in or register to post.
Copyright © 2005 Booleansoup.com
Questions? Comments? Bug reports? Contact us!