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); 
}

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

Leave a Reply