Visual c++ 不允许使用句柄数组C++;
翻译从C#应用程序接收的字符串数组时遇到问题。为什么我不能创建字符串^的数组? 对于C++,我是相当新的,所以任何帮助都是值得赞赏的。Visual c++ 不允许使用句柄数组C++;,visual-c++,c++-cli,string-literals,cross-language,Visual C++,C++ Cli,String Literals,Cross Language,翻译从C#应用程序接收的字符串数组时遇到问题。为什么我不能创建字符串^的数组? 对于C++,我是相当新的,所以任何帮助都是值得赞赏的。 public ref class Example { public: String^ Convert(String^ pointNames[], String^ outputPath) { std::string convertedPath = msclr:
public ref class Example
{
public:
String^ Convert(String^ pointNames[], String^ outputPath)
{
std::string convertedPath = msclr::interop::marshal_as< std::string >(outputPath);
std::string result = otherFunction(pointNames, convertedPath);
return msclr::interop::marshal_as< String^ >(result);
}
};
public ref类示例
{
公众:
字符串^Convert(字符串^POINTNAME[],字符串^outputPath)
{
std::string convertedPath=msclr::interop::marshal_as(outputPath);
std::string result=otherFunction(pointNames,convertedPath);
返回msclr::interop::marshal_作为(结果);
}
};
pointsNames[]下划线为错误,消息为:不允许使用句柄数组
< >从C应用程序向C++发送字符串数组的更好方法是什么?< / P> < P>您试图在那里声明一个非托管数组类型,但是需要托管的类型来保存Manganges类型。 将参数声明为
数组^pointNames
注意:这不是
std::array
,而是在使用/clr
编译时,然后使用namespace cli进行编译代码>是隐含的。快速搜索建议将String^pointNames[]
更改为WriteOnlyArray^pointNames
-你能试试吗?@蓝鱼我不确定我是否理解,我用WriteOnlyArray^替换了String^,但编译器只是说WriteOnlyArray不是模板,我必须包含一些库吗?它似乎属于平台
命名空间下-取自。@Bluefish似乎可以工作,但如何将其转换为字符串[]?如何将cli::array转换为字符串[]?对于这一点,没有像封送那样的内置方法,您只需要编写一个循环并逐个转换每个字符串。