#include <iostream>
#include <fstream>
#include <string>
int main()
{
std::string file_name ;
// repeat for each file name entered by the user
while( std::cout << "\nenter file name (enter an empty string to quit): " &&
std::getline( std::cin, file_name ) && !file_name.empty() )
{
if( std::ifstream input_file{file_name} ) // if the file was opened for input
std::cout << '\n' << input_file.rdbuf() ; // display its contents
else std::cerr << "failed to open input file '" << file_name << "'\n" ;
}
}