![](/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.