Ask Question
16 March, 11:04

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. 16 March, 13:21
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers