Compartilhar via


Como: Converter string padrão sistema::String

Este tópico mostra como converter uma seqüência de caracteres da biblioteca C++ padrão (< Cadeia de Caracteres >) para um String.

Exemplo

// 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.c_str());
   Console::WriteLine(str3);
}

test test test

Consulte também

Referência

Usando a interoperabilidade de C++ (PInvoke implícita)