std没有成员filesystem
时间: 2024-04-14 22:29:25 浏览: 59
对不起,我之前的回答有误。确实,在 C++17 之前,标准库中没有提供 std::filesystem。如果您使用的是旧版的 C++ 标准库,可以考虑使用第三方库来处理文件系统操作,例如 Boost.Filesystem 库。
以下是使用 Boost.Filesystem 库的示例代码:
```cpp
#include <iostream>
#include <boost/filesystem.hpp>
#include <vector>
#include <string>
namespace fs = boost::filesystem;
std::vector<std::string> getAllImageFiles(const std::string& folderPath)
{
std::vector<std::string> imageFiles;
for (const auto& entry : fs::directory_iterator(folderPath))
{
if (entry.status().type() == fs::file_type::regular_file)
{
std::string extension = entry.path().extension().string();
if (extension == ".jpg" || extension == ".jpeg" || extension == ".png" || extension == ".bmp")
{
imageFiles.push_back(entry.path().filename().string());
}
}
}
return imageFiles;
}
int main()
{
std::string folderPath = "path/to/folder";
std::vector<std::string> imageFiles = getAllImageFiles(folderPath);
for (const auto& file : imageFiles)
{
std::cout << file << std::endl;
}
return 0;
}
```
在上述代码中,我们包含了 Boost.Filesystem 头文件,并使用了 `boost::filesystem` 命名空间。剩余的代码与之前的示例相同,只是将 std::filesystem 替换为 boost::filesystem。
请确保在编译和运
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)