JiaHeng-DLUT
11/3/2019 - 2:51 AM

Does a file or folder exist❓

#include <iostream>
#include <string>
#include <sys/stat.h>
using namespace std;

bool doesExist(const std::string& name) {
	struct stat buffer;
	return (stat(name.c_str(), &buffer) == 0);
}

int main() {
	string name = "C:\\Users\\51527\\Desktop";
	cout << doesExist(name) << endl;	// 1
	string name1 = "C:\\Users\\51527\\Desktop1";
	cout << doesExist(name1) << endl;	// 0
	return 0;
}