1. 程式人生 > >C/C++ 中判斷某一檔案或目錄是否存在

C/C++ 中判斷某一檔案或目錄是否存在

1 #include 2 #include 3 4 using namespace std; 5 6 #define FILENAME “*.dat” // 指定檔名 7 8 int main( void ) 9 { 10 fstream _file; 11 _file.open(FILENAME, ios::in); 12 if(!_file) 13 { 14 cout<<FILENAME<<“沒有被建立!”<<endl; 15 } 16 else 17 { 18 cout<<FILENAME<<“已經存在!”<<endl; 19 } 20 21 cin.get(); 22 return 0; 23 }