【发布时间】:2013-03-02 21:59:35
【问题描述】:
我正在尝试编写一个程序来询问他们用户想要读取的文件,当我尝试 myfile.open(fileName) 时,我收到错误:“没有匹配函数调用 std::basic_ifstream<char, std::char_traits<char> >::open(std::string&)'”在那条线。
string filename;
cout<<"Enter name of file: ";
cin>>filename;
ifstream myFile;
myFile.open(filename); //where the error occurs.
myFile.close();
【问题讨论】:
-
令人讨厌的是,cplusplus.com 没有提到自 C++11 以来
open有一个string重载,而 cppreference.com 确实 确实说明了这一点。
标签: c++ string fstream ifstream