Skip to content

Instantly share code, notes, and snippets.

@RyosukeMiyahara
Created March 11, 2014 14:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RyosukeMiyahara/9487364 to your computer and use it in GitHub Desktop.
Save RyosukeMiyahara/9487364 to your computer and use it in GitHub Desktop.
C++でファイルやフォルダが存在するかどうかを確認する
#include <iostream> // cout, endl
#include <sys/stat.h> // stat
int main(void) {
struct stat statFile;
struct stat statDirectory;
struct stat statNothing;
// if file/directory exists, stat() returns 0
// if file/directory does not exist, stat() returns -1
std::cout << stat("file", &statFile) << std::endl;
std::cout << stat("directory", &statDirectory) << std::endl;
std::cout << stat("nothing", &statNothing) << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment