// OpenFile.cc // Program to read data from a file #include #include using namespace std; int main() { char fileName[80]; // Get filename from keyboard input cout << "Enter input file name: "; cin >> fileName; // Declare fin (object) to be of type (class) ifstream // Associate file name with fin ifstream fin; fin.open(fileName); // Prompt for new file name if not able to open while(fin.good() == false) { cout << "Unable to open file. Enter a new name: "; cin >> fileName; // once bad, the file stream will stay bad unless cleared fin.clear(); fin.open(fileName); } }