60 642
Assignments Done
97,8%
Successfully Done
In April 2018

Answer to Question #70555 in C++ for Jacob

Question #70555
Stuck on this problem, can anyone help?

Fill in the following code to crash the program if the file fails to open

#include <iostream>
#include <fstream>
#include<__________>

using namespace std;

int main(){

ifstream.inf;

inf.open("input.txt");

if(!inf){

cout << "Failed to open file" << endl;
___________(_________) // type either true or false in the parenthesis which ever one would make the program crash
}

return 0;

}
Expert's answer
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
ifstream inf;

inf.open("input.txt");

if(!inf){
cout << "Failed to open file" << endl;
exit(1);
}

else
{
cout<<"OK"<<endl;
inf.close(); // close file
}
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions