我正在尝试使用字符串参数打开文件,但是我收到以下错误:
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 *'
如何将System::String ^
转换为const wchar_t *
?
答案 0 :(得分:5)
汉斯指出,简单的转换是必要的。它看起来类似于以下内容:
System::String ^str = L"Blah Blah";
pin_ptr<const wchar_t> convertedValue = PtrToStringChars(str); // <-- #include <vcclr.h>
const wchar_t *constValue = convertedValue; // <-- Unnecessary, but to be completely verbose
void std::basic_ifstream<_Elem, _Traits>::open(constValue, mode, i);