【C/C++文件处理系列】通过stat()函数获取struct 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定义链接

代码实现

#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
$

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值