当前位置:   article > 正文

【C/C++文件处理系列】通过stat()函数获取struct stat结构的信息_c/c++ stat()

c/c++ stat()

【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定义链接

代码实现

  1. #include <sys/stat.h>
  2. #include <sys/types.h>
  3. using namespace std;
  4. int main()
  5. {
  6. int abc;
  7. struct stat mystat;
  8. stat("l_stat.cpp",&mystat);
  9. cout<<"st_dev is:"<<mystat.st_dev<<endl;
  10. cout<<"st_ino is:"<<mystat.st_ino<<endl;
  11. cout<<"st_mode is:"<<mystat.st_mode<<endl;
  12. cout<<"st_nlink is:"<<mystat.st_nlink<<endl;
  13. cout<<"st_uid si:"<<mystat.st_uid<<endl;
  14. cout<<"st_gid is:"<<mystat.st_gid<<endl;
  15. cout<<"st_rdev is:"<<mystat.st_rdev<<endl;
  16. cout<<"st_size is:"<<mystat.st_size<<endl;
  17. cout<<"st_blksize is:"<<mystat.st_blksize<<endl;
  18. cout<<"st_atime is:"<<mystat.st_atime<<endl;
  19. cout<<"st_mtime is:"<<mystat.st_mtime<<endl;
  20. cout<<"st_ctime is :"<<mystat.st_ctime<<endl;
  21. }

编译执行

  1. $
  2. $./a.out
  3. st_dev is:2052
  4. st_ino is:1075119320
  5. st_mode is:33204
  6. st_nlink is:1
  7. st_uid si:500
  8. st_gid is:501
  9. st_rdev is:0
  10. st_size is:644
  11. st_blksize is:4096
  12. st_atime is:1533709432
  13. st_mtime is:1533709432
  14. st_ctime is :1533709432
  15. $

 

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/523270
推荐阅读
相关标签
  

闽ICP备14008679号