C++ cli CLI。如何转换std::vector<;wchar_t>;到System.String^?

C++ cli CLI。如何转换std::vector<;wchar_t>;到System.String^?,c++-cli,marshalling,std,C++ Cli,Marshalling,Std,我需要使用CLIWrapper公开一些非托管数据 我们假设有一个向量,但是向量的中间没有空字符(当然)。进行此类分配/编组的最佳方式是什么 以防万一。。。。如果我将from vector赋值给cli::array,那么相同的操作会是什么样子?您可以直接使用字符串类构造函数。像这样: #include "stdafx.h" #include <vector> using namespace System; int main(array<System::String ^>

我需要使用CLIWrapper公开一些非托管数据

我们假设有一个向量,但是向量的中间没有空字符(当然)。进行此类分配/编组的最佳方式是什么


以防万一。。。。如果我将from vector赋值给cli::array,那么相同的操作会是什么样子?

您可以直接使用字符串类构造函数。像这样:

#include "stdafx.h"
#include <vector>

using namespace System;

int main(array<System::String ^> ^args)
{
    std::vector<wchar_t> example;
    example.push_back('x');
    String^ str = gcnew String(&example[0], 0, example.size());
    Console::WriteLine(str);
    return 0;
}
#包括“stdafx.h”
#包括
使用名称空间系统;
int main(数组^args)
{
std::向量示例;
例如,将_向后推('x');
String^str=gcnewstring(&example[0],0,example.size());
控制台:WriteLine(str);
返回0;
}