簡體   English   中英

C++ 遞歸地遍歷路徑。 錯誤:未找到采用“const std::filesystem::directory_entry”類型的右手操作數的運算符

[英]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.

相關問題 C ++ Boost - 沒有找到哪個運算符采用&#39;boost :: filesystem :: path&#39;類型的右手操作數 重載&lt;&lt;在C ++錯誤中的運算符:::二進制&#39;&lt;&lt;&#39;:找不到使用類型為&#39;const std :: string的右側操作數的運算符 錯誤C ++ 2679(二進制&#39;&gt;&gt;&#39;:找不到使用類型為&#39;const std :: string&#39;的右側操作數的運算符(或沒有可接受的轉換)) 錯誤:C2679二進制&#39;==&#39;:未找到采用類型為&#39;const std :: string&#39;的右側操作數的運算符(或者沒有可接受的轉換 錯誤C2679:二進制&#39;&lt;&lt;&#39;:找不到運算符,該運算符使用類型為&#39;std :: string&#39;的右側操作數 C ++沒有找到需要右手操作數的&lt;&lt;運算符 錯誤 C2679:二進制“&lt;&lt;”:未找到采用“std::vector”類型的右側操作數的運算符<char,std::allocator<char> &gt;&#39; 我如何克服此錯誤C2679:二進制&#39;&gt;&gt;&#39;:未找到采用&#39;const char []&#39;類型的右側操作數的運算符 錯誤C2679:二進制&#39;&gt;&gt;&#39;:未找到采用&#39;const char [4]&#39;類型的右側操作數的運算符(或沒有可接受的轉換)22 錯誤 C2679:二進制“[”:未找到采用“const VerseKey”類型的右側操作數的運算符(或沒有可接受的轉換)
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM