I want to check if a file exists and tried to use the following function
#include <fstream>
bool DoesFileExist(const std::string& filename) {
std::ifstream ifile(filename.c_str());
return (bool)ifile;
}
However, it does not seem to work properly, because instead of checking the existence a file is created! What's the problem here?
Note that I'm forced to use C++98 standard and cannot use #include <sys/stat.h>
or #include <unistd.h>
as suggested in the accepted answer here.