Answer to Question #80831 in C++ for Luke Fisher

Question #80831
Pass in an ifstream (must be a reference argument [what type of parameter is it?]). The
function prompts the user and, if the file is found, it returns true and the ifstream will be a
handle for that text file. Otherwise the function returns false, and the argument is assumed to
be undefined. How does that look code-wise?
1
Expert's answer
2018-09-14T05:49:38-0400
#include <iostream>
#include <fstream>
#include <cstdlib>

char filename[20] = "experiment.txt";
ifstream inpFile;
inpFile.open(filename);
if (!inpFile.is_open())
{
cout << " Could not open the file " << filename << endl;
exit (EXIT_FAILURE);
}

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 the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS