如何:將標準字串轉換為 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.data());
Console::WriteLine(str3);
}
test
test
test
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應