gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 07:28:02 25 4
gpt4 key购买 nike

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

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

最佳答案

谷歌搜索揭示 marshal_as (未经测试):

// marshal_as_test.cpp
// compile with: /clr
#include <stdlib.h>
#include <string>
#include <msclr\marshal_cppstd.h>

using namespace System;
using namespace msclr::interop;

int main() {
std::string message = "Test String to Marshal";
String^ result;
result = marshal_as<String^>( message );
return 0;
}

另见 Overview of Marshaling .

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com