string - 从 std::string 转换为 String^

标签 string c++-cli managed-c++

我在 C++ 中有一个函数,它有一个 std::string 类型的值,我想将它转换为 String^。

void(String ^outValue)
{
   std::string str("Hello World");
   outValue = str;
}

最佳答案

来自 MSDN:

#include <string>
#include <iostream>
using namespace System;
using namespace std;

int main() {
   string str = "test";
   String^ newSystemString = gcnew String(str.c_str());
}

http://msdn.microsoft.com/en-us/library/ms235219.aspx

关于string - 从 std::string 转换为 String^,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45667988/

相关文章:

visual-studio-2008 - 关于 VS2008 C++/CLI 中的重载问题

c++-cli - 是否可以使用 MEF 和 Prism 导出 C++ CLI 接口(interface)

iPhone NSURLConnection : connectionDidFinishLoading - how to return a string to the calling method

string - 在LaTeX中分割逗号分隔的参数

Java Applet - 将文件转换为字符串

c++-cli - 当我包含编码库时出现 C++/CLI 错误 C1189

c# - Asp.net调用C#层调用Managed C++调用Native C++

c# - 从托管 C++ 到 C# 的结构列表

c++-cli - 订阅事件的 C++/CLI 语法是什么?

android - 为什么不在 Activity 之间传递变量值?