C ++ How to determine whether a file exists

Function name: access
Function: determining the access rights of the file
用 法: int access(const char *filename, int amode);
Example of program:
#include <stdio.h>
#include <io.h>
 
int file_exists(char *filename);
 
int main(void)
{
printf("Does NOTEXIST.FIL exist: %s\n",
file_exists("NOTEXISTS.FIL") ? "YES" : "NO");
return 0;
}
 
int file_exists(char *filename)
{
return (access(filename, 0) == 0);
}
 
 
 
access (filename, 0) 0 indicate whether the file exists
 
 
 
 
 
finename mode file name mode, a total of five modes: 0 Check whether the file exists 1- 2- check whether the file can be run to check whether the accessed file is writable-readable file to check whether the access 4- 6- check the file read / write access
 

Guess you like

Origin www.cnblogs.com/blogpro/p/11426666.html