Sunday 30 September 2018

Check for file existence in C++ without creating file

I want to check if a file exists and tried to use the following function



#include 

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 or #include as suggested in the accepted answer here.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...