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.

Recommended Answers

All 7 Replies

This is probably not much help...
but it would seem that a possible reason for your problem could be that you have reached the limit of a float. Maybe you could try using a double or a long?
But I am really sure that a float can store much bigger numbers than this.

>cannot convert parameter 1 from 'std::string' to 'System::String ^'
You're mixing standard C++ strings with C++/CLI strings. There's a fundamental difference in that C++/CLI strings are Unicode based while std::string is char based. The least frustrating solution would be to pick one and stick with it, but you can also convert between the two:

this->InputLabel->Text = gcnew System::String(TotalInput.c_str());

Thanks for the help from both of you, I am going to see what I can do now.

Narue, do you mean that I am trying to mix up two different string classes and should just pick one? Which one would you suggest using, or are they both pretty much the same? The problem I see is that I may have to convert it at certain points.


EDIT

I just tried the conversion that Narue suggested and it hasn't worked. I am still getting strange numbers coming up.

Any more nuggets of wisdom out there?

I am still having problems, if there is anyone else out there that can provide any assistance whatsoever, it would be greatly appreciated.

Bumping your thread multiple times isn't likely to encourage help.

Sorry, but what else am I supposed to do? The last person who posted other than me did so 11 hours ago.

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.