////////////////////////////////////////////////// // // fileInput1.cpp // // Started by Jeff Ondich on 10/7/99 // Last modified 10/11/99 // // This program illustrates the use of the // ifstream type to take input from a file. // Note that the file name ("moose.txt") is // hard-coded into the program. See // fileInput2.cpp for how to get the file name // from the user. // ////////////////////////////////////////////////// #include #include int main( void ) { // Open the file and make sure it's open. ifstream theFile( "moose.txt" ); if( !(theFile.is_open()) ) { cout << "Cannot open moose.txt. Bye." << endl; exit(1); } // Get the words out of the file and do something // with them. string word; while( theFile >> word ) { cout << word << ": " << word.length() << endl; } // Be a good citizen and close the file when // you're done. theFile.close(); return( 0 ); }