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.

Recommended Answers

All 3 Replies

Looking at this page in MSDN I believe you want to use either Convert::ToString(makebreak) or the equivalent Int32::ToString(makebreak).

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.

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.