有没有一种标准的方法可以做findfirst,findnext与gcc在linux上使用stl

Is there a standard way to do findfirst, findnext with gcc on linux using stl?

本文关键字:gcc findnext linux stl findfirst 一种 标准 方法 有没有      更新时间:2023-10-16

我似乎找不到 _findfirst/findfirst, _findnext/findnext API 在 gcc for Linux 上,如果它包含在那里,实际上宁愿使用标准模板库 (STL)。

有谁知道有什么 API 可用于列出 Linux for C++ (gcc) 下的目录中的文件?

不是一个C++式的API,但是你找不到的API(DOS/Windows风格的findfirst/findnext的Linux/Unix通讯员)是opendir/readdir/closedir。

使用 opendir/readdir/closedir 的主要优点是你不需要任何额外的库(它是你已经在使用的 C 库的一部分)。事实上,Boost 文件系统库使用 opendir/readdir/closedir 来获取目录中的文件列表。

引用:

  • http://www.opengroup.org/onlinepubs/009695399/functions/opendir.html
  • http://www.opengroup.org/onlinepubs/009695399/functions/readdir.html
  • http://www.opengroup.org/onlinepubs/009695399/functions/closedir.html

查看 Boost.Filesystem 库。

特别是basic_directory_iterator。

STL 尚不具有列出目录中文件的功能。 但它确实具有打开您已经知道的文件的功能。

除了Boost.Filesystem,还有STLSoft

自 C++17 以来,标准库包含其源代码在 Boost.Filesystem 中的std::filesystem。如今,std::filesystem::directory_iterator是显而易见的选择,因为它与平台无关,提供比_findfirst/findnext/opendir/readdir/closedir更好的抽象,并且不引入任何依赖项。如果无法使用符合 C++17 的编译器,请暂时使用 Boost,稍后再切换。