Converting std::string to System::String ??

Hi all,

I am trying to place the contents of a std::string into a System::String and not having much joy in doing so.

When compiling I receive the error message shown below:

: error C2440: 'initializing' : cannot convert from 'std::string' to 'System::String ^'

Can anyone assist – is there a way I can convert it

Pete



Answer this question

Converting std::string to System::String ??

  • Richard Liu - MSFT

    The c_str() function on a string returns the underlying string data, try using that.



  • IXX.SE

    Fritzables wrote:

    Hi all,

    I am trying to place the contents of a std::string into a System::String and not having much joy in doing so.

    When compiling I receive the error message shown below:

    : error C2440: 'initializing' : cannot convert from 'std::string' to 'System::String ^'

    Can anyone assist – is there a way I can convert it

    Pete

    In addition to CG's suggestion, you can use my StringConvertor class : http://www.codeproject.com/managedcpp/StringConvertor.asp



  • Converting std::string to System::String ??