string data type conversion errors

I have been trying to get a std::string to convert to a system::string, the std one is somehow used by default by the namespace that I have create.

The namespace function that I am trying to use is:

string GetDatah::GetData::monster_name() {

return "Test message!";

}

When I call this function and try and print this message to a windows form label, the compiler comes up with the error:

Error 1 error C2664: 'void System::Windows::Forms::Control::Text::set(System::String ^)' : cannot convert parameter 1 from 'std::string' to 'System::String ^' c:\documents and settings\peter\my documents\visual studio 2005\projects\c++\prorpg\prorpg game engine\prorpg game engine\Form1.h 100

So the function was passed as a std class string, and the windows form uses system strings...

Is there a way to convert the std::string to a system::string....

Please I can't work this out..




Answer this question

string data type conversion errors

  • Gurpreet Singh Gill

    thanks a lot, this saved me hours of attepmting to find a way to make the conversion... :)

  • hemo

    You'll save yourself a lot of grief by locking the std:string class in a closet and throwing away the key. It is grossly incompatible with System::String, wrong character size, wrong encoding and wrong memory model. And Express doesn't give you the ATL conversion functions. Your specific method is easily adapted:

    String^ GetDatah::GetData::monster_name() {
    return "I'm the dot net monstah!";
    }

    If you have to: Marshal.PtrToStringAnsi().


  • string data type conversion errors