Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » U++ users applications in progress and useful code snippets, including reference examples! » Invalid conversion
Invalid conversion [message #7577] Sun, 07 January 2007 13:38 Go to next message
Gatling_Gun is currently offline  Gatling_Gun
Messages: 13
Registered: January 2007
Promising Member
Help me with this code...

char[10] = text1.GetText().ToString();

Ok char to string is an invalid conversion but I try c_str() but don't recognize it!

Please help me! Surprised

[Updated on: Sun, 07 January 2007 13:39]

Report message to a moderator

Re: Invalid conversion [message #7578 is a reply to message #7577] Sun, 07 January 2007 14:50 Go to previous messageGo to next message
Werner is currently offline  Werner
Messages: 234
Registered: May 2006
Location: Cologne / Germany
Experienced Member
Gatling_Gun wrote on Sun, 07 January 2007 13:38

Help me with this code...

char[10] = text1.GetText().ToString();

Ok char to string is an invalid conversion but I try c_str() but don't recognize it!

Please help me! Surprised



"char[10]" seems to be syntactically wrong (unless you use some preprocessor magic). You might try this:

char ten_characters[10];


But why not simply write:

String a_string = text1.GetText();


If "GetText" returns a pointer to an array of chars, this is automatically casted to a String.

Werner
Re: Invalid conversion [message #7579 is a reply to message #7578] Sun, 07 January 2007 15:15 Go to previous messageGo to next message
Gatling_Gun is currently offline  Gatling_Gun
Messages: 13
Registered: January 2007
Promising Member
Yes your right Razz (In a hurry I can make some mistake!).
I need to use the char format to iterate for every char and do some hex conversion.
If i try to use GetText() and pass to the char array it return "invalid initializer" why?

Thx
Re: Invalid conversion [message #7580 is a reply to message #7579] Sun, 07 January 2007 15:18 Go to previous messageGo to next message
Gatling_Gun is currently offline  Gatling_Gun
Messages: 13
Registered: January 2007
Promising Member
If I use this...

char someChar[10] = "Hello!"; <-- It works why? It isn't a string?

Re: Invalid conversion [message #7583 is a reply to message #7580] Sun, 07 January 2007 18:06 Go to previous messageGo to next message
Gatling_Gun is currently offline  Gatling_Gun
Messages: 13
Registered: January 2007
Promising Member
I need to convert the string returned from GetText()to a char!

Help me please! Sad
Re: Invalid conversion [message #7584 is a reply to message #7583] Sun, 07 January 2007 18:36 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
String text = ....
const char *s = text;


(warning: s valid only till next mutating operation on text).

If you really need char[], you can also do this:

char h[...];
strcpy(h, text);


Anyway, beware, there is a danger of buffer overrun (if text.GetLength() is greater than sizeof(h) - 1.)

Alternative, without buffer overrun danger:

Buffer<char> h(text.GetLength() + 1);
memcpy(h, text, text.GetLength() + 1);

[Updated on: Sun, 07 January 2007 18:37]

Report message to a moderator

Previous Topic: Chip 8 Emulator
Next Topic: passing X11 mouse events in spawned process
Goto Forum:
  


Current Time: Fri Mar 29 13:35:35 CET 2024

Total time taken to generate the page: 0.01418 seconds