【问题标题】:WIN32_FIND_DATA equivalent in Linux C++Linux C++ 中的 WIN32_FIND_DATA 等效项
【发布时间】:2017-10-12 08:31:17
【问题描述】:

Linux C++ 中 WIN32_FIND_DATA 的等价物是什么?

WIN32_FIND_DATA fileInfo;

WIN32_FIND_DATA 是 Windows 规范的数据类型。

当我用 C++11 切换到 Linux Centos 7 时,我需要找到它的等价物,因为 WIN32_FIND_DATA 中有几种方法在 Linux 中不支持。

fileInfo.cFileName

【问题讨论】:

标签: c++ linux


【解决方案1】:

C++17 有filesystem

例子:

#include <filesystem>
namespace fs = std::filesystem;

int main()
{
    fs::path p { "/usr/lib/" };
    for (auto& entry : p)
    {
        // do something with entry
    }

    return 0;
}

它基于 Boost 库中的文件系统功能,因此您可以在较旧的编译器中使用它。

【讨论】:

    【解决方案2】:

    stat 结构定义为:(它最接近您的要求)

    struct stat {
        dev_t     st_dev;     /* ID of device containing file */
        ino_t     st_ino;     /* inode number */
        mode_t    st_mode;    /* protection */
        nlink_t   st_nlink;   /* number of hard links */
        uid_t     st_uid;     /* user ID of owner */
        gid_t     st_gid;     /* group ID of owner */
        dev_t     st_rdev;    /* device ID (if special file) */
        off_t     st_size;    /* total size, in bytes */
        blksize_t st_blksize; /* blocksize for file system I/O */
        blkcnt_t  st_blocks;  /* number of 512B blocks allocated */
        time_t    st_atime;   /* time of last access */
        time_t    st_mtime;   /* time of last modification */
        time_t    st_ctime;   /* time of last status change */
    };
    

    否则您必须从头开始构建它,GNU Core Utils 可以提供帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-22
      • 2018-11-26
      • 2012-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多