I have a System Block class that aggregates 2 classes: Mouse and Monitor. All these classes are heirs of the base class: Computer, in which there is a variable: name_of_module and the method that calls this variable. With this function, I get access to the name of the mouse (which is connected to the system unit):

string System_Block::getMouseName() { return Mous.get_name(); } 

Next, I try to assign this Label5 value from the Windows Form:

 std::string namem = Comps[number_of_SB].getMouseName(); label2->Text = System::Convert::ToString(number_of_SB+1); label5->Text = namem;//Здесь ошибка, подсвечивается label5 

But an error occurs:

function "System :: Windows :: Forms :: Label :: Text :: set"

What is the problem?

  • Which line is wrong? - Unick
  • @Unick Tupanul, fixed. - nait123321
  • label5->Text = namem - must be in this one. Type label5->Text probably String^ ? And you are trying to initialize a variable of типа std::string . - isnullxbh
  • @isnullxbh If I do via System::Convert::ToString() , another error will be generated: no instance of overloaded function "System :: Convert :: ToString" matches the argument list - nait123321
  • I speak to you about other line of the code. - isnullxbh

2 answers 2

Try this:

 label5->Text = gcnew System::String(namem.c_str()); 
  • Thanks, it worked!) - nait123321 Nov.
  • @ nait123321: Please! - VladD

Try this:

 label5->Text = String(namem.c_str()); 
  • I c_str() with c_str() , but it doesn’t see such a function at all. - nait123321
  • @ nait123321, do not be fooled, you work with the class std :: string, and c_str () is a method of this class. So if your example did not work for you, it was not because of this. - isnullxbh
  • @ nait123321, most likely the error is that you really need to use the gcnew operator. - isnullxbh