Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

How to: Convert Standard String to System::String

This topic shows how convert a Standard C++ Library string (<string>) to a String.

// 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());

   // alternatively
   String^ str3 = gcnew String(str.c_str());
test test test
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.