Something doesn't make to sense. According to what I've read you use std::filesystem like this:
#include <iostream>
#include <filesystem>
#include <string>
int main()
{
auto iterator = std::filesystem::directory_iterator("c:/somefolder");
for (auto& i : iterator)
{
i.exists();
i.file_size();
}
}
I read the range-based loop as "for each i in iterator, call i.file_size()". With standard containers in C++ this is how it looks, for example a standard vector container.
std::filesystem::directory_iterator seems inconsistent. An iterator is supposed to point to elements in a container, but with std::filesystem::directory_iterator it seems to be a container itself, right? Each i in a range-based loop is a "directory_entry".
If:
std::vector<int> container;
for (auto& i : container)
Is equivalent to:
std::vector<int> container;
for (auto it = std::vector<int>::iterator; it != container.end(); it++)
What's:
for (auto i : iterator)
Equivalent to?
What is happening in the range-based loop above? Is it wrong to read that loop as "for each i in iterator"? The i value is a std::filesystem::directory_entry, but what is being iterated over in the loop? What container?