提问者:小点点

C++递归地遍历一个路径。错误:找不到接受类型为“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


共1个答案

匿名用户

的标准库中没有重载,该重载使用类型为的右手运算符,但是对于存在一个重载,您可以使用方法从获得该重载,因此您应该做的只是转换该行:

致:

相关问题


MySQL Query : SELECT * FROM v9_ask_question WHERE 1=1 AND question regexp '(c++|递归|遍历|路径|找不到|接受|类型|const|std|filesystem|directory_entry|右侧|操作数|运算符)' ORDER BY qid DESC LIMIT 20
MySQL Error : Got error 'repetition-operator operand invalid' from regexp
MySQL Errno : 1139
Message : Got error 'repetition-operator operand invalid' from regexp
Need Help?