Its answered here:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/e7711471-5b3c-489f-9dad-32b37058a689/convert-stdstring-to-systemstring?forum=vclanguage
Putting an object's data member into a form's label
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
However,
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 ?
TIA Bob
3 answers
Sort by: Most helpful
-
-
Jeanine Zhang-MSFT 10,041 Reputation points Microsoft Vendor
2020-12-11T05:16:13.047+00:00 Hi,
I suggest you could refer to the Doc: How to: Convert Standard String to System::String.
Best Regards,
Jeanine
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.
-
srfpala 111 Reputation points
2020-12-12T19:03:01.697+00:00 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 ?
TIA
srfpala