identifier "directory_iterator" is undefined
时间: 2023-07-21 14:04:02 浏览: 41
The identifier "directory_iterator" is a class provided by the C++ Standard Library that allows you to iterate over the contents of a directory. It is part of the "filesystem" library, introduced in C++17. To use the "directory_iterator" class, you need to include the <filesystem> header and use the "std" namespace.
Here's an example of how to use the "directory_iterator" class:
```cpp
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main() {
std::string path = "/path/to/directory";
for (const auto& entry : fs::directory_iterator(path)) {
std::cout << entry.path() << std::endl;
}
return 0;
}
```
Make sure you compile your code with C++17 or later, as the "filesystem" library was introduced in C++17. If you're using an older version of C++, you may need to update your compiler or use alternative libraries like Boost.Filesystem.