Hi guys, good day!
I have a question here pertaining to Visual C++ graphics based. I recently started out incorporating GUI into my C++ programs, in this case, a calculator.
I have a textbox named TextBox1, the user enters the numbers and operators inside it, and when the button is clicked, it outputs the result. Here is a sample input;
4+2
when the user clicks the button, it outputs 6 into a label.
Problem is, I could not obviously use cin here to get the numbers and store into my variables. Can someone show me a very simple code as to how to store 4 and 2 into my variables num1 and num2 and also, store the operator "+" into my variable "operation" of char data type.

Something like this;

double num1, num2;
double result;
num1 = TextBox1->Text; //here is the error
result = num1 + num2;
label1->text = "" + result;

I would expect that TextBox1->Text is a string object of some kind. You cannot assign a string object to a double. You will have to convert the string into a double first.

If you have a compiler that support C++11, there is a function for doing this: http://en.cppreference.com/w/cpp/string/basic_string/stof

I guess it is not your intention to "parse" an "expression".
So I suggest to use two textboxes. One for num1, the other for num2.
Next use an operator button(+,-,. . .)
and using the suggestion by Moschops to update your label text.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.