If you are already using the input file stream class (ifstream
), you could use its function fail()
.
Example:
ifstream myFile;
myFile.open("file.txt");
// Check for errors
if (myFile.fail()) {
cerr << "Error: File could not be found";
exit(1);
}