1.C++很简单的一种办法:
#include <iostream>
#include <fstream>
using namespace std;
#define FILENAME "stat.dat"
int main()
{
fstream _file;
_file.open(FILENAME,ios::in);
if(!_file)
{
cout<<FILENAME<<"没有被创建";
}
else
{
cout<<FILENAME<<"已经存在";
}
return 0;
}
  2.利用 c 语言的库的办法:
  函数名: access
  功  能: 确定文件的访问权限
  用  法: int access(const char *filename, int amode);
  以前一直没用过这个函数,调试程序发现了这个函数,感觉挺好用,尤其是判断一个文件或文件夹是否存在的时候,用不着再find了,文件的话还可以检测读写权限,文件夹的话则只能判断是否存在,下面摘自MSDN:
int_access(constchar*path,intmode);
ReturnValue
Eachofthesefunctionsreturns0ifthefilehasthegivenmode.Thefunctionreturns–1ifthenamedfiledoesnotexistorisnotaccessibleinthegivenmode;inthiscase,errnoissetasfollows:
EACCES
Accessdenied:file’spermissionsettingdoesnotallowspecifiedaccess.
ENOENT
Filenameorpathnotfound.
Parameters
path
Fileordirectorypath
mode
Permissionsetting
Remarks
Whenusedwithfiles,the_accessfunctiondetermineswhetherthespecifiedfileexistsandcanbeaccessedasspecifiedbythevalueofmode.Whenusedwithdirectories,_accessdeterminesonlywhetherthespecifieddirectoryexists;inWindowsNT,alldirectorieshavereadandwriteaccess.
modeValueChecksFileFor
00Existenceonly
02Writepermission
04Readpermission
06Readandwritepermission
Example
/*ACCESS.C:Thisexampleuses_accesstocheckthe
*filenamed"ACCESS.C"toseeifitexistsandif
*writingisallowed.
*/
#include<io.h>
#include<stdio.h>
#include<stdlib.h>
voidmain(void)
{
/*Checkforexistence*/
if((_access("ACCESS.C",0))!=-1)
{
printf("FileACCESS.Cexists");
/*Checkforwritepermission*/
if((_access("ACCESS.C",2))!=-1)
printf("FileACCESS.Chaswritepermission");
}
}
Output
FileACCESS.CexistsFileACCESS.Chaswritepermission