Write an if statement to halt program if the program fails t

Write an if statement to halt program if the program fails to opne a file. Assuem the file to be opened has name \"stats.dat\".

Solution

C++ program

#include <iostream>
#include <fstream>
using namespace std;

int main () {
ifstream infile;
infile.open (\"stats.dat\");
if (infile.is_open())
{
while (infile.good())
cout << \"file opened successfully\" << endl;
infile.close();
}
else
{
cout << \"Error opening file\";
}
return 0;
}

Write an if statement to halt program if the program fails to opne a file. Assuem the file to be opened has name \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site