How to check if a file exists in C++

To check if a file exists in C++ you can use the following snippet.

Sample C++

#include <sys/stat.h>

inline bool fileExists (const std::string& fileName) {
	struct stat buff;   
	return (stat (fileName.c_str(), &buff) == 0); 
}

Please Share us:
Please rate this snippet

One thought on “How to check if a file exists in C++

Leave a Reply