糖尿病康复,内容丰富有趣,生活中的好帮手!
糖尿病康复 > struct stat结构体的详解和用法

struct stat结构体的详解和用法

时间:2022-12-14 18:48:05

相关推荐

struct stat结构体的详解和用法

[cpp]view plaincopy//!需要包含de头文件#include<sys/types.h>#include<sys/stat.h>

S_ISLNK(st_mode):是否是一个连接.

S_ISREG(st_mode):是否是一个常规文件.

S_ISDIR(st_mode):是否是一个目录

S_ISCHR(st_mode):是否是一个字符设备.

S_ISBLK(st_mode):是否是一个块设备

S_ISFIFO(st_mode):是否 是一个FIFO文件.

S_ISSOCK(st_mode):是否是一个SOCKET文件

intstat(constchar*filename,structstat*buf);//!prototype,原型structstat{dev_tst_dev;/*IDofdevicecontainingfile-文件所在设备的ID*/ino_tst_ino;/*inodenumber-inode节点号*/mode_tst_mode;/*protection-保护模式?*/nlink_tst_nlink;/*numberofhardlinks-链向此文件的连接数(硬连接)*/uid_tst_uid;/*userIDofowner-userid*/gid_tst_gid;/*groupIDofowner-groupid*/dev_tst_rdev;/*deviceID(ifspecialfile)-设备号,针对设备文件*/off_tst_size;/*totalsize,inbytes-文件大小,字节为单位*/blksize_tst_blksize;/*blocksizeforfilesystemI/O-系统块的大小*/blkcnt_tst_blocks;/*numberofblocksallocated-文件所占块数*/time_tst_atime;/*timeoflastaccess-最近存取时间*/time_tst_mtime;/*timeoflastmodification-最近修改时间*/time_tst_ctime;/*timeoflaststatuschange-*/};

[cpp]view plaincopy#include<iostream>#include<ctime>#include<sys/types.h>#include<sys/stat.h>usingnamespacestd;intmain(){structstatbuf;intresult;result=stat("./Makefile",&buf);if(result!=0){perror("Failed^_^");}else{//!文件的大小,字节为单位cout<<"sizeofthefileinbytes:"<<buf.st_size<<endl;//!文件创建的时间cout<<"timeofcreationofthefile:"<<ctime(&buf.st_ctime)<<endl;//!最近一次修改的时间cout<<"timeoflastmodificationofthefile:"<<ctime(&buf.st_mtime)<<endl;//!最近一次访问的时间cout<<"timeoflastaccessofthefile:"<<ctime(&buf.st_atime)<<endl;}return0;}

[cpp]view plaincopy$./testsizeofthefileinbytes:36timeofcreationofthefile:SunMay2418:38:10timeoflastmodificationofthefile:SunMay2418:38:10timeoflastaccessofthefile:SunMay2418:38:13

如果觉得《struct stat结构体的详解和用法》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。