Condividi tramite


Procedura: convertire stringhe standard in System::String

In questo argomento viene illustrato come convertire una stringa di libreria standard C++ (<stringa>) in un oggetto String.

Esempio

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

Vedi anche

Uso delle funzionalità di interoperabilità C++ (PInvoke implicito)