Converting std::String to System::String

Any easy way?
From MSVC2008 Help:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// convert_standard_string_to_system_string.cpp
// compile with: /clr
#include <string>
#include <iostream>
using namespace System;
using namespace std;

int main() {
   string str = "test";
   cout << str << endl;
   String^ str2 = gcnew String(str.c_str());
   Console::WriteLine(str2);

   // alternatively
   String^ str3 = gcnew String(str.c_str());
   Console::WriteLine(str3);
}
Last edited on
Topic archived. No new replies allowed.