从std :: string转换为String ^ [英] convert from std::string to String^

查看:888
本文介绍了从std :: string转换为String ^的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a function in C++ that have a value in std::string type and would like to convert it to String^.

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


推荐答案

Google搜索显示 marshal_as (未经测试):

Googling reveals marshal_as (untested):

// 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;
}

另请参见封送处理概述

这篇关于从std :: string转换为String ^的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆