Managed C ++中的字符串数组 [英] Arrays of strings in Managed C++

查看:150
本文介绍了Managed C ++中的字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我试图在Managed C ++中编写一个应用程序,但我无法确定如何声明一个字符串数组。 String ^ linet [];


引发错误


'System :: String ^':本机数组不能包含此托管类型


为托管数据类型执行此操作。

解决方案

你真的是指Managed C ++吗?不是C ++ / CLI?



假设你实际上使用C ++ / CLI(因为你发布的错误信息),有两种方法:

  array< String ^> ^ managedArray = gcnew array< String ^>(10) 

将创建一个托管数组,即与C#中的string []类型相同。

  gcroot< String ^> [] unmanagedArray; 

将创建一个非托管C ++数组(我从来没有实际尝试过数组 - stl容器,所以它也应该在这里工作)。


I'm trying to write an application in Managed C++, but I cannot work out how to declare an array of strings.

String^ linet[];

throws an error

'System::String ^' : a native array cannot contain this managed type

So I suppose there's a different way to do this for managed data types. What exactly is it?

解决方案

Do you really mean Managed C++? Not C++/CLI?

Assuming you're actually using C++/CLI (because of the error message you posted), there are two ways to do this:

array<String^>^ managedArray = gcnew array<String^>(10);

will create a managed array, i.e. the same type as string[] in C#.

gcroot<String^>[] unmanagedArray;

will create an unmanaged C++ array (I've never actually tried this with arrays - it works well with stl containers, so it should work here, too).

这篇关于Managed C ++中的字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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