/* F.T. Liu * 1/10/03 * Demonstration program for Comp 1672 * Reviews how to handle input from files */ #include #include #include using namespace std; int main() { string filename; int search_num, num_from_file; ifstream input_file; // Give user message program summary cout << "This program asks you for a file name and a number. It\n"; cout << "then tells you whether or not that number appears in the file.\n"; // Get the filename and search number from the user cout << "Please input the filename: "; cin >> filename; cout << "Please input the integer you want to search for: "; cin >> search_num; // Open the file - exit program if it can't be opened input_file.open(filename.c_str()); if (!input_file.is_open()) { cout << "Unable to open file " << filename << endl; return 1; } // Look for the search number in the file until we reach end of file while (!input_file.eof()) { // get the next number out of the file input_file >> num_from_file; if (input_file) { // If we found a match, say so, and we're done! if (num_from_file == search_num) { cout << "The number " <