• 0

TextField->Text to char something[200] = error!


Question

Hi, when I use char location[200] = textBox3->Text;

and it gives me this error:

error C2440: 'initializing' : cannot convert from 'System::String __gc *' to 'char [200]'

There are no conversions to array types, although there are conversions to references or pointers to arrays

any ideas?

11 answers to this question

Recommended Posts

  • 0
  Tikitiki said:
Hi, when I use char location[200] = textBox3->Text;

and it gives me this error:

error C2440: 'initializing' : cannot convert from 'System::String __gc *' to 'char [200]'

There are no conversions to array types, although there are conversions to references or pointers to arrays

any ideas?

586422961[/snapback]

Out of curiosity, why do you want to used a fixed buffer? Why not use System::String instead?

Also, in Managed C++, you'd use a capitalized Char(represents a Unicode character) to refer to the Value type in the CLI. Add to that that in .NET you don't need to specify the array size for managed types.

Char location[];

location = textBox3->Text->ToCharArray();

Now, if you're trying to convert to an unmanaged type, that's a little more involved. If that's the case, I'll post how to do it.

  • 0
  weenur said:
Out of curiosity, why do you want to used a fixed buffer? Why not use System::String instead?

Cause im a n00b!

  Quote
Also, in Managed C++, you'd use a capitalized Char(represents a Unicode character) to refer to the Value type in the CLI. Add to that that in .NET you don't need to specify the array size for managed types.

Char location[];

location = textBox3->Text->ToCharArray();

Now, if you're trying to convert to an unmanaged type, that's a little more involved. If that's the case, I'll post how to do it.

586425511[/snapback]

Okey well, now it doesn't give me the error when compiling but what it outputs is not what I want :blink:

Say I put in this: C:\\Documents and Settings\{YOUR USERNAME}\Application Data\Atari\RCT3\Options.txt

The ouput will be: Xl?

:((

Also, I dont know if this is managed c++ or not. How would I tell?

  • 0
  Tikitiki said:
I am putting that into a text box, then I click save and it saves it to a text file. Then when I click the refresh button, it will read the text file and set the text of the file to the text box.

Its managed then!

586427404[/snapback]

Well, you could have a managed console app, too. Regardless, this should be pretty simple to do.

    System::String* location = textBox3->Text;
    StreamWriter* sw = new StreamWriter(S"Test.txt", false);
    
    // this is a bit redundant as you could
    // just write textBox1->Text to the file.
    sw->WriteLine(location);
    
    sw->Close();

in your read code you'd do this:

  if(File::Exists(S"Test.txt")==true
  	StreamReader* sr = new StreamReader(S"Test.txt");
  	String* location = sr->ReadLine();
  	
  	if(location != NULL && location->Length > 0)
    textBox1->Text = location;
  	
  	sr->Close();
  }

  • 0

I get a whole bunch of errors. Am I missing an include? A namespace?

error C2653: 'File' : is not a class or namespace name

warning C4805: '==' : unsafe mix of type ''unknown-type'' and type 'bool' in operation

error C3861: 'Exists': identifier not found, even with argument-dependent lookup

error C2065: 'StreamReader' : undeclared identifier

error C2065: 'sr' : undeclared identifier

error C2061: syntax error : identifier 'StreamReader'

error C2227: left of '->ReadLine' must point to class/struct/union

type is ''unknown-type''

error C3861: 'sr': identifier not found, even with argument-dependent lookup

error C2227: left of '->Close' must point to class/struct/union

type is ''unknown-type''

error C3861: 'sr': identifier not found, even with argument-dependent lookup

  • 0

Great! I dont get any errors now, but say I put this in a text field: C:\\Documents and Settings\{YOUR USERNAME}\Application Data\Atari\RCT3\Options.txt and press save.

The output would be $?

egh! oh and btw ToCharArray doesn't work!:((

  • 0
  Tikitiki said:
Great! I dont get any errors now, but say I put this in a text field: C:\\Documents and Settings\{YOUR USERNAME}\Application Data\Atari\RCT3\Options.txt and press save.

The output would be $?

egh! oh and btw ToCharArray doesn't work!:((

586432694[/snapback]

Would you mind showing me how you're doing it?

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.