Putting an object's data member into a form's label

srfpala 111 Reputation points

Thanks to DavidLowndes-6766 for previous help
In Win 10 using VS2019
Given a Window DeskTop App:
lblNumber->Text = System::Convert::ToString(myObj.myNum); // Works
lblText->Text = "Some test data"; // Works

lblText->Text = myObj.myString; // Fails even though myString is type string

If I can copy a string literal into a form's label, why can't I copy
a string object member into a form's label called lblText->Text ?
Generated Error C2664 is - 'void System::Windows::Forms::Control::Text::set(System::String ^)': cannot convert argument 1 from 'std::string' to 'System::String ^'
What should I do ?

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,525 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Jeanine Zhang-MSFT 9,101 Reputation points Microsoft Vendor


    I suggest you could refer to the Doc: How to: Convert Standard String to System::String.

    Best Regards,


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. srfpala 111 Reputation points

    Reviewed previous discussion and thankx but
    Question continues
    // ========== OBJECTIVE copy the myObj.myString data member into a form's label
    class MyClass { // This class is defined in MyClass.h
    public: // Access specifier
    int myNum; // Attribute (int variable)
    string myString; // Attribute (string variable)

        lblText->Text = "Some test data"; // Testing - So the form's label exists and 
                                           // accepts a literal   which may or may not be a string ?????
        lblText->Text = myObj.myString;  // Failure 1 - rejects the object's string data 
                                         //   member .... BUT WHY ? 

    Still confused
    Any suggestions ?