C/C++???ж????????????????
???????????? ???????[ 2015/4/9 12:00:50 ] ????????C++ ??? ?? ???? API
????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
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11