// Mr. Minich
// CMPSC 201
// Ch. 8 Demo Program #4
// January 20, 2000 // Purpose - to illustrate how to detect the end of a file while reading that file
#include <iostream>
#include <fstream>
using namespace std; int main() { int secretNumber = 0; ifstream passwordFile;
// passwordFile is a file pointer to a file that is opened for input. passwordFile.open("secret.txt");
// opens the file named "secret.txt" // for input. The file must be // located in the same directory // (folder) as the .cpp source file do
{ passwordFile >> secretNumber; if (!passwordFile.eof()) { cout << "The secret number is " << secretNumber << endl; }
} while(!passwordFile.eof()); // this loop detects the end of the file return 0; }// end of main