Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System::String^ to int conversion in VC 2005

Status
Not open for further replies.

Gaffi1

Technical User
Apr 23, 2004
70
0
0
US
Hello. I'm still fairly new to C++, and I'm using the cookie-cutter style coding built into Visual Studio 2005 to help me out. From there, I'm adding additional code as needed.

What this means for me is, when I have a text box on a form, the default type of the Text field seems to be System::String^.

I'm trying to take a user input of integers in the text boxes to output to a binary file. Then, that file is made available to another program. I've got the file i/o all figured out, but when I try to take the value of the text box, I get an error that I can't convert from 'System::String ^' to 'int'.

This make sense to me as well, but I can't figure out how to get the data type of the text box to default to int (or maybe there is another method of doing what I am trying to do...). I have tried to cast with (int) and static_cast<int>, but these did not help.

I noticed that on other forms controls (for example, the progress bar control) there is a property called 'Value', but this is just not present for the text box control.

Here is what I am currently doing in short form...

Code:
int Value1;
Value1 = this->Value1TextBox->Text;
(write Value1 to file with int type)

Is there any way to make this conversion or is there another way to do this?

Thanks very much!
 
Ok... I've figured it out, though I found very little information about this method in books or google...

This is the correct conversion (or at least it's one way that works):
Code:
int Value1;
Value1 = System::Convert::ToInt32(this->Value1TextBox->Text);
(write Value1 to file with int type)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top