CLI。如何将std :: vector <wchar_t>转换为System.String ^?</wchar_t>

时间:2012-08-21 17:15:37

标签: c++-cli marshalling std

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

假设我有一个向量,但向量中间没有空字符(当然)。做这种类型的分配/编组的最佳方法是什么?

以防万一......如果我从vector到cli :: array分配相同的操作怎么样?

1 个答案:

答案 0 :(得分:2)

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

#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;
}
相关问题