방법: 표준 문자열을 System::String으로 변환

이 항목에서는 표준 C++ 라이브러리 문자열(<string>)을 String으로 변환하는 방법을 보여 줍니다.

예제

// 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);
}
  

참고 항목

참조

C++ Interop 사용(암시적 PInvoke)