Vis C++ using integers and text box

Bg computers / N/A
January 21, 2009 at 07:59:31
Specs: Windows XP, Quad Duo - 256mb
Hello All

I am trying to learn to use Visual Studio to make a C++ program.

I am having problem taking the contents of a textbox and using them as an integer.

I want first assign the current contents of one textbox to an int variable, and the contents of a second text box to a second int variable.

I am then going to add them together and display them on a label.

What ever i try it wont build and I get errors that tell me the string cant be converted to the integer.

Can anyone tell me the correct way of doing this?

I then want to add them together

See More: Vis C++ using integers and text box

Report •

January 22, 2009 at 02:13:45
You could try posting some code (between the "pre" and "/pre" tags that are inserted when you press the "pre" icon) to show us how you are currently attempting to convert the text box contents to an integer, and we'll try and tell you (if we can) where you went wrong.

Report •

January 22, 2009 at 02:45:11
This was how I first tried to do it

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
			int twidth; //tile width
			int thight; //tile hight


Report •

January 22, 2009 at 05:55:03
You are using C++/CLI for the .NET platform. C++/CLI is a different language to C++. I don't know C++/CLI. But from a C++ point of view, I would #include <cstdlib> and use twidth = std::atoi(textBox1->Text);

Report •

Related Solutions

January 23, 2009 at 00:44:52
I see. Does this mean I cant use Visual Studio 2008 to make C++ windows programs (not console programs)?

If I can use Visual Studio, how do i go about creating a C++ Windows app?

Report •

January 23, 2009 at 02:08:32
Visual Studio allows you to program in several languages: Visual Basic, C#, C++/CLI and C++. The first three target the .NET platform. The last one targets the Win32 platform. With either platform, you can write both console and GUI applications.

If you want to write a GUI (i.e. Windows application) in C++, you can either use Standard C++ and a Win32 windowing toolkit, such as MFC, WTL or the Win32 API; or you can use C++/CLI with the .NET platform, which offers a different set of windowing classes to the Win32 ones. .NET applications, such as the one you started writing, require that the user has the .NET Framework installed on his machine. Recent versions of Windows (such as Vista and XP SP3) will already have it installed. Otherwise, you will need to redistribute the .NET Framework with your application (unless you are just writing it for your own use.)

Apart from that, you'll probably find that using .NET makes programming easier than using older technologies such as MFC. C++/CLI is based on Standard C++ but contains lots of language extensions that make the syntax incompatible with Standard C++. But if you are only targetting the .NET platform, and are not worried about keeping to standards, then there's no reason not to use C++/CLI - except, maybe, that C# is much easier to use.

Report •

Ask Question