日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

struct stat结构体的详解和用法

發(fā)布時間:2023/11/27 生活经验 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 struct stat结构体的详解和用法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
[cpp]?view plaincopy
  1. //!?需要包含de頭文件??
  2. ??
  3. #include?<sys/types.h>??
  4. ??
  5. #include?<sys/stat.h>???

?

S_ISLNK(st_mode):是否是一個連接.
S_ISREG(st_mode):是否是一個常規(guī)文件.
S_ISDIR(st_mode):是否是一個目錄
S_ISCHR(st_mode):是否是一個字符設(shè)備.
S_ISBLK(st_mode):是否是一個塊設(shè)備
S_ISFIFO(st_mode):是否 是一個FIFO文件.
S_ISSOCK(st_mode):是否是一個SOCKET文件?

?

?

?

  1. ??
  2. int?stat(const?char?*filename,?struct?stat?*buf);?//!?prototype,原型???
  3. ??
  4. struct?stat??
  5. {??
  6. ??
  7. ????dev_t???????st_dev;?????/*?ID?of?device?containing?file?-文件所在設(shè)備的ID*/??
  8. ??
  9. ????ino_t???????st_ino;?????/*?inode?number?-inode節(jié)點號*/??
  10. ??
  11. ????mode_t??????st_mode;????/*?protection?-保護模式?*/??
  12. ??
  13. ????nlink_t?????st_nlink;???/*?number?of?hard?links?-鏈向此文件的連接數(shù)(硬連接)*/??
  14. ??
  15. ????uid_t???????st_uid;?????/*?user?ID?of?owner?-user?id*/??
  16. ??
  17. ????gid_t???????st_gid;?????/*?group?ID?of?owner?-?group?id*/??
  18. ??
  19. ????dev_t???????st_rdev;????/*?device?ID?(if?special?file)?-設(shè)備號,針對設(shè)備文件*/??
  20. ??
  21. ????off_t???????st_size;????/*?total?size,?in?bytes?-文件大小,字節(jié)為單位*/??
  22. ??
  23. ????blksize_t???st_blksize;?/*?blocksize?for?filesystem?I/O?-系統(tǒng)塊的大小*/??
  24. ??
  25. ????blkcnt_t????st_blocks;??/*?number?of?blocks?allocated?-文件所占塊數(shù)*/??
  26. ??
  27. ????time_t??????st_atime;???/*?time?of?last?access?-最近存取時間*/??
  28. ??
  29. ????time_t??????st_mtime;???/*?time?of?last?modification?-最近修改時間*/??
  30. ??
  31. ????time_t??????st_ctime;???/*?time?of?last?status?change?-?*/??
  32. ??
  33. };??

[cpp]?view plaincopy
  1. #include?<iostream>??
  2. ??
  3. #include?<ctime>??
  4. ??
  5. #include?<sys/types.h>??
  6. ??
  7. #include?<sys/stat.h>???
  8. ??
  9. using?namespace?std;???
  10. ??
  11. int??
  12. main?()??
  13. {??
  14. ????struct?stat?buf;??
  15. ??
  16. ????int?result;??
  17. ??
  18. ????result?=?stat?("./Makefile",?&buf);??
  19. ??
  20. ????if?(result?!=?0)??
  21. ??????{??
  22. ??????????perror?("Failed?^_^");??
  23. ??????}??
  24. ????else??
  25. ??????{??
  26. ??
  27. ??????????//!?文件的大小,字節(jié)為單位??
  28. ??
  29. ??????????cout?<<?"size?of?the?file?in?bytes:?"?<<?buf.st_size?<<?endl;??
  30. ??
  31. ??????????//!?文件創(chuàng)建的時間??
  32. ??
  33. ??????????cout?<<?"time?of?creation?of?the?file:?"?<<?ctime?(&buf.st_ctime)?<<??
  34. ??
  35. ??????????????endl;??
  36. ??
  37. ??????????//!?最近一次修改的時間??
  38. ??
  39. ??????????cout?<<?"time?of?last?modification?of?the?file:?"?<<??
  40. ??
  41. ??????????????ctime?(&buf.st_mtime)?<<?endl;??
  42. ??
  43. ??????????//!?最近一次訪問的時間??
  44. ??
  45. ??????????cout?<<?"time?of?last?access?of?the?file:?"?<<?ctime?(&buf.st_atime)??
  46. ??
  47. ??????????????<<?endl;??
  48. ??????}??
  49. ??
  50. ????return?0;??
  51. ??
  52. }??

[cpp]?view plaincopy
  1. $?./test??
  2. ??
  3. size?of?the?file?in?bytes:?36??
  4. ??
  5. time?of?creation?of?the?file:?Sun?May?24?18:38:10?2009??
  6. ??
  7. time?of?last?modification?of?the?file:?Sun?May?24?18:38:10?2009??
  8. ??
  9. time?of?last?access?of?the?file:?Sun?May?24?18:38:13?2009 ?


?

轉(zhuǎn)載于:https://www.cnblogs.com/wxmdevelop/p/4649495.html

總結(jié)

以上是生活随笔為你收集整理的struct stat结构体的详解和用法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。