Skip to main content
gamedev.net
🔒 Locked

String to Int

Started by DorRaba May 4, 2004 at 8:53 AM 2 replies 250+ views
Original Post
DorRaba
DorRaba
Hi I''m working with visual C++ .NET and I have created a text box that is going to have a number, and the number will go into an integer variable, but I can''t do it, this is my code, please help me: int num; num = textBox1->Text; error: d:\Tzipi Project\Printing 1.01\Printing 1.01\Costumer.h(110): error C2440: ''='' : cannot convert from ''System::String __gc *'' to ''int''
DDDDor RRRRaba
MauMan
MauMan
int num = Int32::Parse( textBox1->Text );  


But be warned if textBox1->Text contains non-integer characters with will throw an expection so guard such code with an exception handler.

Edit: Realized we were talking about managed C++ not C#

[edited by - mauman on May 4, 2004 10:16:03 AM]
---CyberbrineDreamsSuspected implementation of the Windows idle loop: void idle_loop() { *((char*)rand()) = 0; }
nate0326
nate0326
num = atoi(textBox1->Text);

The atoi function converts a string to an integer.

It is in the standard C runtime libraries.

You need to include stdlib.h.
DorRaba
DorRaba
Thank guys, you both helped me, thanks alot.
DDDDor RRRRaba

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.