Matt
Matt

Reputation: 89

File stream with inputted file name

I want to prompt the user for the file name then use that name to open up a file stream. I think I need to make it into a const char or something but I dont really know what that is or how to do so.

cout << "Enter Locations Filename: "<<endl;
cin>> locFilename;

ifstream locations(locFilename);

Upvotes: 1

Views: 60

Answers (1)

Thomas Matthews
Thomas Matthews

Reputation: 57749

Here's the correction:

cout << "Enter Location's Filename: ";
getline(cin, locFilename);
ifstream locations(locFilename.c_str();

Input and output are two separate functions in C++. Some versions of C++ require a C-style string for the file open method.

Upvotes: 1

Related Questions