本文介绍了从System :: String ^到const wchar_t的字符串转换*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用字符串参数打开文件,但是出现以下错误:
I'm trying to open a file using a string parameter, however I'm getting the following error:
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 *
?
推荐答案
正如汉斯所指出的,简单的转换是必要的.它看起来类似于以下内容:
As Hans points out, simple conversion is necessary. It would look similar to the following:
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);
这篇关于从System :: String ^到const wchar_t的字符串转换*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!