![](/img/trans.png)
[英]C++ Boost - no operator found which takes a right-hand operand of type 'boost::filesystem::path'
[英]C++ iterate through a path recursively. Error: no operator found which takes a right-hand operand of type 'const std::filesystem::directory_entry'
我想创建一个循环遍历路径中的所有文件夹和文件。 我有以下代码(如此处所述)
#include <filesystem>
#include <iostream>
for (const auto& dirEntry : std::filesystem::recursive_directory_iterator("some path here")) {
std::cout << dirEntry;
}
但是,我收到以下错误:
'<<': no operator found which takes a right-hand operand of type 'const std::filesystem::directory_entry' (or there is no acceptable conversion)
谁能解释我如何解决这个问题? 我正在使用 C++17
operator<<
的标准库中没有重载,它采用std::filesystem::directory_entry
类型的右手运算符,但std::filesystem::path
存在一个,您可以从std::filesystem::directory_entry
使用path()
方法,所以你应该做的就是转换这一行:
std::cout << dirEntry;
至:
std::cout << dirEntry.path();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.