在vc ++中将列表转换为char ** [英] convert list to char** in vc++
本文介绍了在vc ++中将列表转换为char **的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
char **details;
list->Add(gcnew String("Test String 1"));
list->Add(gcnew String("Test String 2"));
list->Add(gcnew String("Test String 3"));
String^ filterTxt = "two";
for(int i=0;i<3; i++)
{
details[i]=(char*)(void*)Marshal::StringToHGlobalAnsi(list[i]);
Console::WriteLine(details[i]);
}
Console::ReadLine();
上面的代码得到空引用异常,请帮我解决这个问题。
The above code getting the null reference exception, please help me on this.
推荐答案
好吧,也许,如果你为细节分配了一些实际内存,那么错误就会消失?
你将它声明为指向char的指针:
Well, perhaps, if you assigned some actual memory to details the error would go away?
You declared it as a pointer-to-pointer-to char:
char **details;
接下来你要做的就是尝试填充它:
And the next thing you do with it is try to fill it up:
details[i]=(char*)(void*)Marshal::StringToHGlobalAnsi(list[i]);
你真的没有指出任何事情......
At no point do you actually point it at anything...
这篇关于在vc ++中将列表转换为char **的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文