I'm using fstream library to work with files. Basically, I need to know if a certain file exists or not. In c++ documentation online, about open(), it reads:
Return Value
none
If the function fails to open a file, the failbit state flag is set for the stream (which may throw ios_base::failure if that state flag was registered using member exceptions).
It says not return value is specified. But in case of failure, a flag is set. My question is that, I should I then access that flag, or to better ask, how should I see if open()
is successful or not.
I have this code so far:
int Log::add()
{
fstream fileStream;
fileStream.open("logs.txt");
}
fileStream.is_open()
? en.cppreference.com/w/cpp/io/basic_ifstream/is_open – Alexis Wilkefail
andbad
which can be tested, but it does not tell you whether the file was protected or did not exist or the path was wrong... – Alexis Wilke