Created
March 11, 2014 14:51
-
-
Save RyosukeMiyahara/9487364 to your computer and use it in GitHub Desktop.
C++でファイルやフォルダが存在するかどうかを確認する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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