Skip to content

Latest commit

 

History

History
43 lines (35 loc) · 1.12 KB

how-to-convert-standard-string-to-system-string.md

File metadata and controls

43 lines (35 loc) · 1.12 KB
descriptiontitlems.customms.datehelpviewer_keywordsms.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
C++ Standard Library, converting strings to System::String
string conversion [C++], C++ Standard Library string
strings [C++], converting
1fde79a0-9d0b-44e5-981b-e8f2676c199d

How to: Convert Standard String to System::String

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

Example

// 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 

See also

Using C++ Interop (Implicit PInvoke)

close