#include #include // for ifstream #include #include "prompt.h" // count integers in a file int main() { int num; // current number int count = 0; // counter for the number of integers string s; ifstream input; string filename = PromptString("enter name of file: "); input.open(filename.c_str()); // bind input to named file if (input.fail()) // if filename is invalid { cout << "cannot open " << filename << endl; return 0; //stop program } while (!input.eof()) // until the end of the file { // read the next number and check if it is really an integer if (input >> num) { cout << num << "\tvalid \n"; count++; // if integer count it } else // otherwise clear the error flags and skip the invalid entry { input.clear(); input >> s; cout << s << "\tinvalid \n"; } } cout << "\ntotal number of integers is " << count <