A simple method: # Include <iostream> # Include <fstream> Using namespace STD; # Define FILENAME "Stat. dat" Int main () { Fstream _ file; _ File. Open (filename, IOS: In ); If (! _ File) { Cout <FILENAME <"not created "; } Else { Cout <FILENAME <"already exists "; } Return 0; } Another method to use the C language library: Function Name: Access Skill: determine the object access permission Usage: int access (const char * filename, int amode ); ProgramExample: # 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 indicates checking whether the file exists Finename file name mode: 0-check whether the file exists 1-check whether the file is running 2-check whether the file is writable 4-check whether the file is readable 6-check whether the file is readable/written for access |