首页 > 编程知识 正文

access和c语言哪个好,access数据库函数

时间:2023-05-06 12:10:44 阅读:35538 作者:4440

在Linux上,access函数的声明在unistd.h文件中声明如下:

int access (常数char * pathname,int mode ); 访问函数可以是指定的文件或目录是否存在(F_OK )、已存在的文件或目录可读(R_OK )、可写(W_OK )、可执行(X_OK F_OK、R_OK、W_OK和X_OK这四种方法由access函数的第二个参数mode指定。 如果指定的方法有效,则此函数返回0,否则返回-1。

Windows中没有访问函数,但io.h文件中有_access函数,声明如下:

int_access(constchar*_filename,int _ access模式); windows下的函数_access与linux下的access函数类似,只在指定的文件或目录中存在[00],在现有文件或目录中存在只读[04],只写[ 这四种方法由_access函数的第二个参数mode指定。 如果mode接收到0、2、4或6以外的值,则调用此函数时为crash。 如果指定的方法有效,则此函数返回0,否则返回-1。

以下是测试代码(access.cpp )。

# include ' access.HPP ' # include iostream # include vector # include string # ifdef _ MSC _ ver # io.h # else # include ifdef _ MSC _ verconststd 33603360 string path { ' e :/git code } const STD :3360 vectorconststd :3360 string names { } for(autoname:names ) const STD 33603360 string tmp=pathname; fprintf(stdout,' fileordirectoryname :' % s' : ',name.c_str ) ); if(access ) tmp.c_str (,0 )==0) fprintf ) stdout,' exist,'); ELSEfprintf(stdout,' not exist,'); if (访问(tmp.c _ str ),4 )==0) fprintf ) stdout,' only has read premission,'); ELSEfprintf(stdout,' does not have read premission,'); if (访问(tmp.c _ str ),2 )==0) fprintf ) stdout,' only has write premission,'); ELSEfprintf(stdout,' does not have write premission,'); if (访问) tmp.c_str (,6 )==0) fprintf ) stdout,' hasbothreadandwritepremission (n ' ); ELSEfprintf(stdout,' hasneitherreadnorwritepremissionn ' ); } # elseconststd :3360 vectorconstchar * names { ' test data ',' CMakeLists.txt ',' build.sh ',' invalid'}; for (自动命名) fprintf ) stdout,' fileordirectoryname : (% s (' : ',name ) ); if(access(name,F_OK )==0) fprintf ) stdout,' exist,'); ELSEfprintf(stdout,' not exist,',name ); if(access(name,R_OK )==0) fprintf ) stdout,' has read premission,'); ELSEfprintf(stdout,' does not have read premission,'); if (访问(name,W_OK )==0) fprintf ) stdout,' has write premission,'); ELSEfprintf(stdout,' does not have write premission,'); if (访问(name,X_OK )==0) fprintf ) stdout,' has execute premissionn ' ); ELSEfprintf(stdout,' does not have execute premissionn ' ); }#endifreturn 0; }} //namespace access_在Linux上的运行结果如下。

3358 www.Sina.com/: https://github.com//fengbing chun/messy _ test

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。