有没有一种标准的方法可以做findfirst,findnext与gcc在linux上使用stl
Is there a standard way to do findfirst, findnext with gcc on linux using stl?
我似乎找不到 _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,稍后再切换。
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 奇怪的结构&GCC&clang(void*返回类型)
- GCC本机矩阵运算库
- PowerPC ppc64le上的Gcc Woverloaded虚拟错误
- gcc和c++17的过载解析失败
- 数据成员SFINAE的C++17测试:gcc vs clang
- GCC对可能有效的代码抛出init list生存期警告
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- 使用 GCC 卸载的 OpenMP 卸载失败,并出现"Ptx assembly aborted due to errors"
- 为什么与常规GCC不同,即使有"学究性错误",MinGW-GCC也能容忍丢失的返回类型
- 使用gcc从静态链接的文件中查找可选符号
- 普通环路未使用gcc 4.8.5自动矢量化
- 有了gcc,是否可以链接库,但前提是它存在
- 在clang++预处理器中确定gcc工具链版本
- 为什么 gcc 编译这个而 msvc 没有
- 为什么lambda在clang上崩溃而不是在gcc上崩溃
- 我可以检测和更改 gcc/g++ 中结构的当前数据对齐设置吗?
- gcc和clang在表达式是否为常量求值的问题上存在分歧
- 如何使用Clang/GCC在Mac上为C/C++设置VSCode
- 有没有一种标准的方法可以做findfirst,findnext与gcc在linux上使用stl