Trying to ask user for a file name to input

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&)'|
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).
Worked perfect. Thank you!
Topic archived. No new replies allowed.