我在c#中有一个windows表单应用程序,它使用c ++中的函数.这是使用c ++包装器完成的.但是,该函数需要使用指针,而c#不允许使用带字符串数组的指针.可以做些什么来克服这个问题?我已经阅读了使用marshal但我不确定这是否适用于这种情况,如果是这样,应该如何与我的代码集成.以下是C#代码:
int elements = 10;
string [] sentence = new string[elements];
unsafe
{
fixed (string* psentence = &sentence[0])
{
CWrap.CWrap_Class1 contCp = new CWrap.CWrap_Class1(psentence, elements);
contCp.getsum();
}
}
Run Code Online (Sandbox Code Playgroud)
c ++函数声明:
funct::funct(string* sentence_array, int sentence_arraysize)
c ++包装器:
CWrap::CWrap_Class1::CWrap_Class1(string *sentence_array, int sentence_arraysize)
{
pcc = new funct(sentence_array, sentence_arraysize);
}
我正在尝试使用字符串参数打开文件,但是我收到以下错误:
error C2664: 'void std::basic_ifstream<_Elem,_Traits>::open(const wchar_t *,std::ios_base::openmode,int)' : cannot convert parameter 1 from 'System::String ^' to 'const wchar_t *'
Run Code Online (Sandbox Code Playgroud)
你怎么转换System::String ^成const wchar_t *?