如何:将标准字符串转换为 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 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈