Ask Question

What is the missing If condition in the following code fragment? The program is supposed to halt if the input file does not exist. ifstream inFile; inFile. open ("myfile. dat"); if () { cout << "Cannot open input file." << endl; return 1;

+1
Answers (1)
  1. 29 August, 03:11
    0
    The missing part is

    if (! inFile)

    Explanation:

    The full codes are as follows:

    ifstream inFile; inFile. open ("myfile. dat"); if (! inFile) { cout << "Cannot open input file." << endl; return 1; } return 0;

    Given that inFile is an ifstream object. When inFile is used to open "myfile. data", there will be possibility where myfile. dat is not available. If so,! inFile will be interpolated as true in the if condition and generate the message "Cannot open input file". This is one very simple way to check if the file exist when we try to read it from our program.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “What is the missing If condition in the following code fragment? The program is supposed to halt if the input file does not exist. ifstream ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers