#include #include using namespace std; int main() { // declare variables ifstream myfile; string s; // open file for reading myfile.open( "hello.dat" ); // make sure file is opened okay if ( ! myfile ) { cout << "error opening file :-(\n"; exit( 1 ); } cout << "file opened a-okay :-)\n"; // read contents of file until there's nothing left while ( ! myfile.eof() ) { // myfile >> s; getline( myfile, s ); if ( ! myfile.eof() ) { cout << "s=" << s << endl; } } // end of while // close file myfile.close(); } // end of main()