赞
踩
【stat】
函数原型:
stat() stats the file pointed to by path and fills in buf
获取指定路径的文件信息并保存到struct stat类型的结构体中
int stat(const char *path, struct stat *buf);
struct stat 结构体 详见struct stat定义链接
代码实现
- #include <sys/stat.h>
- #include <sys/types.h>
- using namespace std;
- int main()
- {
- int abc;
- struct stat mystat;
- stat("l_stat.cpp",&mystat);
-
- cout<<"st_dev is:"<<mystat.st_dev<<endl;
- cout<<"st_ino is:"<<mystat.st_ino<<endl;
- cout<<"st_mode is:"<<mystat.st_mode<<endl;
- cout<<"st_nlink is:"<<mystat.st_nlink<<endl;
- cout<<"st_uid si:"<<mystat.st_uid<<endl;
- cout<<"st_gid is:"<<mystat.st_gid<<endl;
- cout<<"st_rdev is:"<<mystat.st_rdev<<endl;
- cout<<"st_size is:"<<mystat.st_size<<endl;
- cout<<"st_blksize is:"<<mystat.st_blksize<<endl;
- cout<<"st_atime is:"<<mystat.st_atime<<endl;
- cout<<"st_mtime is:"<<mystat.st_mtime<<endl;
- cout<<"st_ctime is :"<<mystat.st_ctime<<endl;
-
- }

编译执行
- $
- $./a.out
- st_dev is:2052
- st_ino is:1075119320
- st_mode is:33204
- st_nlink is:1
- st_uid si:500
- st_gid is:501
- st_rdev is:0
- st_size is:644
- st_blksize is:4096
- st_atime is:1533709432
- st_mtime is:1533709432
- st_ctime is :1533709432
- $
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。