Trying to ask user for a file name to input
Nov 23, 2013 at 8:56pm UTC
I would like to ask the user for a file name to input, cin that file name, and then load it into the ifstream. For example...
1 2 3 4 5 6
string inputFile;
cout << "Please enter the file you would like to input: " ;
cin >> inputFile;
ifstream fin(inputFile);
But I keep on getting an error that says...
error: no matching function for call to 'std::basic_ifstream<char>::basic_ifstream(std::string&)'|
Nov 23, 2013 at 9:01pm UTC
Try ifstream fin(inputFile.c_str());
The more recent compilers will accept either version. The older way uses a c-string (null-terminated character array).
Nov 23, 2013 at 9:08pm UTC
Worked perfect. Thank you!
Topic archived. No new replies allowed.