How to use TextBox text in c++ form?

10,538

Please include following header file

#include <msclr\marshal_cppstd.h>

then try

msclr::interop::marshal_context context;
std::string std_string= context.marshal_as<std::string>(name_2door_txt->Text);

If you want to convert to managed string

System::String^ managed_string = name_2door_txt->Text;
Share:
10,538
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    I want to know is there anyone that knows how I can assign textbox text in C++ windowsform to a string?
    In c# it's like for example:

    string name;
    name=textbox1.Text;
    

    but in C++ I don't know how it works. I've tried this:

    string name;
    name = name_2door_txt->Text;
    

    but visual give me this error:

        IntelliSense: no operator "=" matches these operands
            operand types are: std::string = System::String ^   
    

    and I need it to be a string. Could you please help?