F
fl
Hi,
Below the dot line is a function except from C++ primer, 4th edition. When I use this function, I suspect the open operation fails. I do not know how to check the "in" stream status. The curious thing is that it mentioned open state in the comment part below, but there is nothing to do that (at least I do not find it).
Could you tell me how to check "in" stream?
Thanks,
................
#include "io_preamble.h"
// opens in binding it to the given file
ifstream& open_file(ifstream &in, const string &file)
{
in.close(); // close in case it was already open
in.clear(); // clear any existing errors
// if the open fails, the stream will be in an invalid state
in.open(file.c_str()); // open the file we were given
return in; // condition state is good if open succeeded
}
Below the dot line is a function except from C++ primer, 4th edition. When I use this function, I suspect the open operation fails. I do not know how to check the "in" stream status. The curious thing is that it mentioned open state in the comment part below, but there is nothing to do that (at least I do not find it).
Could you tell me how to check "in" stream?
Thanks,
................
#include "io_preamble.h"
// opens in binding it to the given file
ifstream& open_file(ifstream &in, const string &file)
{
in.close(); // close in case it was already open
in.clear(); // clear any existing errors
// if the open fails, the stream will be in an invalid state
in.open(file.c_str()); // open the file we were given
return in; // condition state is good if open succeeded
}