Share via


方法 : 標準文字列を System::String に変換する

更新 : 2007 年 11 月

このトピックでは、標準 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);
}

test
test
test

参照

参照

C++ Interop (暗黙の PInvoke) の使用