The operator `<<` not overloaded for `directory_entry`.

I'm using Apple Clang on macOS 11.5.2. When I try to compile the following code:

#include <fstream>
#include <iostream>
#include <filesystem>
 
int main()
{
    const std::filesystem::path sandbox{"sandbox"};
    std::ofstream{sandbox/"file1.txt"};
    std::ofstream{sandbox/"file2.txt"};
 
    std::cout << "directory_iterator:\n";
    for(auto const& dir_entry: std::filesystem::directory_iterator{sandbox})
        std::cout << dir_entry << '\n';
 
    std::filesystem::remove_all(sandbox);
}

Via the command clang++ foo.cpp -std=c++17 , I get:

foo.cpp:13:19: error: invalid operands to binary expression ('std::__1::ostream' (aka 'basic_ostream<char>') and 'const std::__1::__fs::filesystem::directory_entry')
        std::cout << dir_entry << '\n';

I'm having a similar issue using my directory_iterator in a normal do loop:

do { cout << *dir_walker << '\n'; dir_walker++; } while (dir_walker != directory_iterator{}); I used the C++17 setting in XCode 13.1. When I run clang++ from the command line, it says:

$ clang++ --version Apple clang version 13.0.0 (clang-1300.0.29.3) Target: x86_64-apple-darwin20.6.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin Please help!

P.S. -- Sorry I could not figure out how to make this look better. It just smooshes it all together when I hit Submit.

The operator &#96;&lt;&lt;&#96; not overloaded for &#96;directory_entry&#96;.
 
 
Q