Search code examples
c++-cli

Convert standard C++ int to String^


I want to convert std::int to System::String^ in Visual C++/CLI enviroment. I know that we can use the library provided by Microsoft that include template function marshal_as

#include <msclr\marshal.h>

using namespace msclr::interop;

int count = 1;
String^ Apple;
Apple = marshal_as<String^>(count);

I couldn't run this statement as I got this error

'msclr::interop::error_reporting_helper<_To_Type,_From_Type,false>::marshal_as':
 This conversion is not supported by the library or the header file needed for 
this conversion is not included.

Solution

  • int count = 100; 
    System::String^ s = count.ToString();