C++ - no operator "<<" matches these operands directory_iterator()

bork

I've copied the example code on the directory_iterator page, so this is what I have:

#include "pch.h" //for visual studios benefit
#include <fstream>
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;

int main()
{
    fs::create_directories("sandbox/a/b");
    std::ofstream("sandbox/file1.txt");
    std::ofstream("sandbox/file2.txt");
    for (auto& p : fs::directory_iterator("sandbox"))
        std::cout << p << '\n'; //this line on the first '<<' is where the error occurs
    fs::remove_all("sandbox");
    return 0; //included by me
}

And the error message is:

Severity    Code    Description Project File    Line    Suppression State
Error (active)  E0349   no operator "<<" matches these operands 

As I'm new to C++ I might have gotten things wrong, but my understanding of the error is basically that p in my case is something which can't be printed out to the console using cout.

The example works if I run it directly on the page so there isn't something wrong with it, which I wouldn't expect either. So question is, why am I seeing this error?

I use the latest version of Visual Studio, along with C++ 2017.

T.C.

directory_entry doesn't have streaming support directly; it gets it via path's operator<< plus an implicit conversion to const std::filesystem::path &.

As a result of LWG issues 2989 and 3065, path's operators have been made into hidden friends, and can no longer be used to stream things convertible to a path, such as a directory_entry.

The fix is to ask for .path() directly rather than depend on the implicit conversion. I've fixed the cppreference example.


After checking with LWG, this change appears to be unintended. I've filed LWG 3171.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

IntelliSense: no operator "<<" matches these operands

error: no operator "<" matches these operands

C++ - Error - No operator "[]" matches these operands

Error during implementation of operator>> :C++ no operator matches these operands operand types are: std::istream >> const double error

more than one operator "[]" matches these operands

No operator "<<" matches these operands - C++

C++) E0349 no operator matches these operands occured

no operator ">>" matches these operands -- operand types are: std::istream >> const double

Accessing an entry in std::map causes 'no operator "[]" matches these operands'

No operator "<" matches these operands operand types are: double < my_class

no operator ""<<"" matches these operands error

Error : no operator " != " matches these operands

no operator ">>" matches these operands operand types are: std::istream >> double*

No operator "+" matches these operands, aka cannot add Array<double> to double

No Operator = Matches Operands - DX11

no operator matches these operands; operand types are: std::istream >> const char [5]

E0349 no operator ">>" matches these operands

C++ No operator [] matches these operands

Error: no operator "==" matches these operands

No operator ">=" matches these operands error in c++ when using while loop

no operator "=" matches these operands error

No Operator ">>" matches these operands operand types are: std::istream>>int

"no operator >> matches these operands"

No operator "<<" matches these operands error between an object and a string literal

no operator "<<" matches these operands recursive tower of hanoi error

No operator "[ ]" matches these operands C++

no operator "/" matches these operands

Error C++: no operator matches these operands. operand types are: std::ostream << void

E0349 no operator "<<" matches these operands