使用字符串作为打开文件路径的C ++ ifstream错误。
|
我有:
string filename:
ifstream file(filename);
编译器抱怨ifstream文件和字符串不匹配。我需要将文件名转换为其他内容吗?
这是错误:
error: no matching function for call to ‘std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(std::string&)’
/usr/include/c++/4.4/fstream:454: note: candidates are: std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]
没有找到相关结果
已邀请:
3 个回复
迪擅哨乘傅
至
因为
的构造函数需要
,而不是
C ++ 11之前的版本。
期差骇蓟
构造函数期望
,因此您需要执行
使其生效。
仇聘发栖