How to: Convert Standard String to System::String
This topic shows how convert a C++ Standard Library string (<string>) to a String.
Example
// 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.data());
Console::WriteLine(str3);
}
test
test
test
See also
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for