I can't figure out how to convert my int value back to a string for use in a textbox. I already pulled it out converted it to int, did the equation now I just want to flip it back to display in a textbox.

    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {

                int cost = Convert::ToInt32(costbuy->Text);
                int amount = Convert::ToInt32(amountb->Text);
                int costnow = Convert::ToInt32(nowcost->Text);
                int frontcost = cost*amount;
                int endcost = costnow*amount;
                int makebreak = endcost-frontcost;
                string makebreak1 = makebreak.ToString();
                ;
                end->Text = makebreak;

             }

It's a stock value calculator if that helps make sense of the code.

It is probably a simply typo. The string conversion produces a .NET string of type System::String^, not a C++ string of type std::string. If you use the lower-case name string, my guess is that it refers to std::string, which is not the same as System::String^. This should work:

System::String^ makebreak1 = makebreak.ToString();

If you want a C++ string, then you will have to marshal the .NET String.

It is probably a simply typo. The string conversion produces a .NET string of type System::String^, not a C++ string of type std::string. If you use the lower-case name string, my guess is that it refers to std::string, which is not the same as System::String^. This should work:

System::String^ makebreak1 = makebreak.ToString();

If you want a C++ string, then you will have to marshal the .NET String.

Absolutely beautiful. Thanks mike, and everyone else who contributed as well! Helping me understand more and more.

This article has been dead for over six months. Start a new discussion instead.