c/c++判断文件是否存在
- stat
#include <sys/stat.h>
bool isFileExist(const std::string name)
{
struct stat buffer;
return (stat (name.c_str(), &buffer) == 0);
}
- access
#include <unistd.h>
#include <fcntl.h>
bool isFileExist(const std::string name)
{
return ((access("mytest.c",F_OK))!=-1) ;
}