how to find out if a directory exists in cpp

Solutions on MaxInterview for how to find out if a directory exists in cpp by the best coders in the world

showing results for - "how to find out if a directory exists in cpp"
Simon
08 Jan 2020
1#include <sys/stat.h>
2
3bool IsPathExist(const std::string &s)
4{
5  struct stat buffer;
6  return (stat (s.c_str(), &buffer) == 0);
7}
8
Peyton
18 Sep 2017
1#include <sys/stat.h>
2
3int main() {
4	struct stat buffer;
5    std::string string = "Hello";
6    
7    if (stat(&string.c_str(), &buffer) != 0) {
8    	std::cout << "'Hello' directory doesn't exist!";
9    } else {
10    	std::cout << "'Hello' directory exists!";
11    }
12}