[英]how to choose a specific direcrory entry within directory iterator
我的問題很具體,抱歉。
從這段代碼:
int i = 0;
for(auto& p: recursive_directory_iterator("stru1")) {
++i;
cout << "Index no." << i << p.path() << '\n';
在此循環將遍歷目錄中的每個實體和 output 路徑及其索引號。
我的問題是,在循環完成后,是否有任何地方可以選擇特定索引並顯示索引目錄的內容?
確定您獲得相同條目(如果對該目錄有並發修改)的唯一方法是在迭代期間構建一個向量:
std::size_t i = 0;
std::vector<std::filesystem::directory_entry> entries;
for(auto& p: std::filesystem::recursive_directory_iterator("stru1")) {
++i;
std::cout << "Index no." << i << p.path() << '\n';
entries.push_back(p);
}
if (std::cin >> i && i >= 1 && i <= entries.size()) {
auto const & entry = entries[i - 1];
// use entry
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.