zoukankan      html  css  js  c++  java
  • _access在哪里声明

    Determine file-access permission.

    int _access( const char
    *path, int mode );

    声明于      io.h   
    #include  <io.h>

    C++ _access和_waccess的使用方法

    概述

    头文件:<io.h> 判断文件的访问权限

    原型

    int _access(

        const char *path,     int mode );

    int _waccess( 

        const wchar_t *path,     int mode );

    参数

    path

    文件或目录路径

    mode

    访问权限设定

    返回值

    如果文件具有指定的访问权限,则函数返回0;如果文件不存在或者不能访问指定的权限,则返回-1。

    备注

    当path为文件时,_access函数判断文件是否存在,并判断文件是否可以用

    mode值指定的模式进行访问。当path为目录时,_access只判断指定的目录是否存

    在,在Windows NT和Windows 2000中,所有的目录都有读写权限。

    mode的值和含义如下表所示: mode值

    检查文件

    00 只检查文件是否存在 02 写权限 04 读权限 06

    读写权限

    _waccess是_access的宽字符版本,_waccess的参数path为宽字符的字符串,

    其他与_access相同。

    实例

    该实例使用_access判断文件是否存在,并判断文件是否可写。

    // crt_access.c

     #include  <io.h>

     #include  <stdio.h>

     #include  <stdlib.h> 

    int main( void ) {

       /* 判断文件是否存在 */

       if( (_access( "crt_ACCESS.C", 0 )) != -1 )    {

          printf( "File crt_ACCESS.C exists " );       /* 判断文件是否可写 */       /* 假设文件时只读的 */

          if( (_access( "crt_ACCESS.C", 2 )) == -1 )

             printf( "File crt_ACCESS.C does not have write permission " );   

    }

    }

    输出:

    File crt_ACCESS.C exists

    File crt_ACCESS.C does not have write permission

  • 相关阅读:
    Linux命令全训练
    解决maven中静态资源只能放到properties中的问题
    Mybatis出现错误org.apache.ibatis.executor.ExecutorException: No constructor found in
    Fence Repair
    Saruman's Army
    Best Cow Line
    区间调度问题
    硬币问题
    迷宫最短路径
    Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A. Oath of the Night's Watch
  • 原文地址:https://www.cnblogs.com/hualimengyu/p/3472708.html
Copyright © 2011-2022 走看看