description | title | ms.custom | ms.date | helpviewer_keywords | ms.assetid | |||
---|---|---|---|---|---|---|---|---|
Learn more about: How to: Convert Standard String to System::String | How to: Convert Standard String to System::String | get-started-article | 11/04/2016 |
| 1fde79a0-9d0b-44e5-981b-e8f2676c199d |
This topic shows how convert a C++ Standard Library string (<string>) to a xref:System.String.
// convert_standard_string_to_system_string.cpp// compile with: /clr #include<string> #include<iostream>usingnamespaceSystem;usingnamespacestd;intmain() { string str = "test"; cout << str << endl; String^ str2 = gcnew String(str.c_str()); Console::WriteLine(str2); // alternatively String^ str3 = gcnew String(str.data()); Console::WriteLine(str3); }
test test test