Jan 30, 2018 at 4:56am UTC
I get an error that says, "no matching function." On the line with the file.open() function.
#include <iostream>
#include <fstream>
using namespace std;
int main(){
string name;
ifstream file;
cout << "Enter the file name: ";
getline(cin, name);
file.open(name);
return 0;
}
Last edited on Jan 30, 2018 at 4:57am UTC
Jan 30, 2018 at 8:56am UTC
That function accepts a string parameter only from C++11 onwards. If you have an old compiler, get a new one, or use the other version of the function, that accepts a char* (
file.open(name.c_str());
) .
http://www.cplusplus.com/reference/fstream/ifstream/open/
This is the year 2018, and many good modern compilers are free. You should get one.
Last edited on Jan 30, 2018 at 8:56am UTC
Jan 30, 2018 at 3:55pm UTC
I am using c++11 and i still get that error message for some reason. But I've tried it with .c_str() and now it works fine.
thanks for the help.