I've been working on a file reader that reads the data from inside the file and stores it in a string. My code compiles how it should when I hard-code the file name to be opened, but when I try to read in the file from the keyboard I get the error "no known conversion for argument 1 from str to const and I don't know why. Heres my code:
#include <iostream>
#include <fstream>
#include <string>
int main() {
string fileName;
cout << "Enter the file name to be read: ";
cin >> fileName;
ifstream input_file(fileName);
std::string line_; // string which text file contents will be stored in
if(input_file.is_open()){ // validation to see if the file is open
while(getline(input_file, line_)){
std::cout<<line_<< '\n'; //prints the contents of the file into the console
}
input_file.close();
}
else {
std::cout<<"File is not open"<< '\n';
}
std::cin.get();
}