identifier "directory_iterator" is undefined
时间: 2023-07-21 22:04:02 浏览: 118
The "directory_iterator" identifier is used in C++ to iterate over the contents of a directory. This feature is available in the Standard Library starting from C++17. To use it, you need to include the <filesystem> header and use the std::filesystem namespace.
Here's an example of how to use directory_iterator:
```cpp
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main() {
fs::path directoryPath = "path/to/directory";
for (const auto& entry : fs::directory_iterator(directoryPath)) {
std::cout << entry.path() << std::endl;
}
return 0;
}
```
Make sure your compiler supports C++17 or later, and you have included the <filesystem> header.
阅读全文