Sunday, September 30, 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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...