Frage

I need a little help with my calculator program. I have created the code for the main buttons like the numbers 0-9 and the arithmetic operators to make it perform simple calculations.

What I'm having problems with right now is making the CE button work, after clicking the CE button I need the last entered character to be removed from the display label.

I have tried to adapt this code somehow, but it doesn't work:

lblResult->substr(0, lblResult->size()-1);

I know I'm doing somehting wrong here, can you please help me?

Thanks in advance

War es hilfreich?

Lösung

...Now that we know that lblResult is a System.Windows.Forms.Label, we can look at the documentation.

A Label has a Text Property, which is a String^ (i.e. a string reference).

For what you want to do, the Remove Method of String is appropriate. But note in the documentation it says that it "Returns a new string in which a specified number of characters from the current string are deleted." This means that it does not modify the string, but returns a modified copy.

So to change the label's text, we need to assign to its Text property what we want: the current string with all of the characters except the last:

lblResult->Text = lblResult->Text->Remove(lblResult->Text->Length - 1);

Andere Tipps

lblResult->resize(lblResult->size() - 1);

In this case you can use components Remove and Length methods.

Use the following code to access the components text:

component->Text

Than remove the last character of string by accessing Remove and component Length method

= component->Text->Remove(component->Text->Length - 1)

I hope you find this useful.

Just asking the obvious -- the whole statement is

*lblResult = lblResult->substr(0, lblResult->size()-1);

right?

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top