1234567891011121314151617181920
#include <iostream> #include <fstream> #include <string> int main() { std::string fname ; std::cout << "file name? " ; std::getline( std::cin, fname ) ; // http://en.cppreference.com/w/cpp/io/basic_ifstream/rdbuf // overload (9) http://en.cppreference.com/w/cpp/io/basic_ostream/operator_ltlt if( std::cout << std::ifstream(fname).rdbuf() ) ; // on success, do nothing more else // the attempt to dump the contents of the file to stdout failed { std::cerr << "could not open '" << fname << "' for input\n" ; return 1 ; } }