Hey guys, I was wondering if any of you could help me with some stuff which may seem obvious to you but I'm a beginner.
I'm making a calculator and have reached the part where I am making the buttons change the string on the calculator's "screen".
The way I am doing this is by getting the current line of numbers as a string and then converting the number pressed into a string and then adding the two strings together to form the new calculator display, I then want to display that string.
After reading some books and looking online I thought the best way of doing this would be to use string streaming, so I have made the following:
if(ButtonType == 1) // Numerical buttons processed here
{
CurrentInputString = "";
CurrentInput = 0;
CurrentInput = ButtonNumber;
InputOutputStream << CurrentInput;
InputOutputStream >> CurrentInputString;
InputOutputStream.str("");
InputOutputStream.clear();
InputOutputStream << TotalInput;
InputOutputStream >> TotalInputString;
InputOutputStream.str("");
InputOutputStream.clear();
InputOutputStream << TotalInputString << CurrentInputString;
//TotalInputString += CurrentInputString;
InputOutputStream >> TotalInput;
InputOutputStream << TotalInput;
InputOutputStream >> TotalInputString;
InputOutputStream.str("");
InputOutputStream.clear();
this->InputLabel->Text = Convert::ToString(TotalInput);
}
I had problems setting the text as "TotalInputString" and got these compiler messages:
error C2664: 'void System::Windows::Forms::Control::Text::set(System::String ^)' : cannot convert parameter 1 from 'std::string' to 'System::String ^'
1> No user-defined-conversion operator available, or
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Therefore I decided to change it by converting the TotalInput float to a string, which worked but the calculator would only allow me to input 7 numbers before showing "Infinite" on the calculator display and then any further input would result in the first number being a "1" despite pressing any of the buttons.
So my question is - how do I do this? All I want is for the string to allow me to place as many numbers as I need on the display. How do I change the text in such a way?
This was done on Visual C++, sorry if that's a problem.
Thanks in advance to anyone who helps.