C++ - no operator “<<” matches these operands directory_iterator()
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
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.
c++ visual-studio-2017
add a comment |
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.
c++ visual-studio-2017
add a comment |
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.
c++ visual-studio-2017
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.
c++ visual-studio-2017
c++ visual-studio-2017
edited Nov 22 '18 at 11:11
gsamaras
52.8k25110197
52.8k25110197
asked Nov 22 '18 at 11:06
borkbork
6463929
6463929
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
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.
Hmm, I am not sure now whether my answer is correct after reading yours T.C, nice answer!
– gsamaras
Nov 22 '18 at 11:20
I don't know if I'm in a position to determine if usingpath()
or theexperimental
namspace is more correct than the other. So I won't accept an answer until I get more enlighted within the subjet. They both work however, rendering a slightly different output. Usingpath()
will render "" around each find, whileexperimental
namespace will not. The data is still the same though.
– bork
Nov 22 '18 at 13:38
experimental
gets you the older filesystem TS implementation, which will be removed in the next ABI-breaking release of MSVC.
– T.C.
Nov 22 '18 at 15:30
add a comment |
Change this:
namespace fs = std::filesystem;
to this:
namespace fs = std::experimental::filesystem;
because VS 17 uses an experimental version of the filesystem
.
add a comment |
For Visual Studio 2017 (15.8 and 15.9 if I'm not mistaken), filesystem
only exposes an experimental version, so use:
namespace fs = std::experimental::filesystem;
add a comment |
Use the std::experimental
namespace:
namespace fs = std::experimental::filesystem;
1
Hey Peter, I believe you are right, but I don't see what that answer adds further than my answer and Matthieu's... :/
– gsamaras
Nov 22 '18 at 11:17
Yes you're right. I just tried the sample in vs2017 and posted the answer here. Sorry, I didn't see your answers.
– Peter
Nov 22 '18 at 11:24
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53429574%2fc-no-operator-matches-these-operands-directory-iterator%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Hmm, I am not sure now whether my answer is correct after reading yours T.C, nice answer!
– gsamaras
Nov 22 '18 at 11:20
I don't know if I'm in a position to determine if usingpath()
or theexperimental
namspace is more correct than the other. So I won't accept an answer until I get more enlighted within the subjet. They both work however, rendering a slightly different output. Usingpath()
will render "" around each find, whileexperimental
namespace will not. The data is still the same though.
– bork
Nov 22 '18 at 13:38
experimental
gets you the older filesystem TS implementation, which will be removed in the next ABI-breaking release of MSVC.
– T.C.
Nov 22 '18 at 15:30
add a comment |
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.
Hmm, I am not sure now whether my answer is correct after reading yours T.C, nice answer!
– gsamaras
Nov 22 '18 at 11:20
I don't know if I'm in a position to determine if usingpath()
or theexperimental
namspace is more correct than the other. So I won't accept an answer until I get more enlighted within the subjet. They both work however, rendering a slightly different output. Usingpath()
will render "" around each find, whileexperimental
namespace will not. The data is still the same though.
– bork
Nov 22 '18 at 13:38
experimental
gets you the older filesystem TS implementation, which will be removed in the next ABI-breaking release of MSVC.
– T.C.
Nov 22 '18 at 15:30
add a comment |
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.
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.
edited Dec 12 '18 at 0:13
answered Nov 22 '18 at 11:19
T.C.T.C.
108k14222331
108k14222331
Hmm, I am not sure now whether my answer is correct after reading yours T.C, nice answer!
– gsamaras
Nov 22 '18 at 11:20
I don't know if I'm in a position to determine if usingpath()
or theexperimental
namspace is more correct than the other. So I won't accept an answer until I get more enlighted within the subjet. They both work however, rendering a slightly different output. Usingpath()
will render "" around each find, whileexperimental
namespace will not. The data is still the same though.
– bork
Nov 22 '18 at 13:38
experimental
gets you the older filesystem TS implementation, which will be removed in the next ABI-breaking release of MSVC.
– T.C.
Nov 22 '18 at 15:30
add a comment |
Hmm, I am not sure now whether my answer is correct after reading yours T.C, nice answer!
– gsamaras
Nov 22 '18 at 11:20
I don't know if I'm in a position to determine if usingpath()
or theexperimental
namspace is more correct than the other. So I won't accept an answer until I get more enlighted within the subjet. They both work however, rendering a slightly different output. Usingpath()
will render "" around each find, whileexperimental
namespace will not. The data is still the same though.
– bork
Nov 22 '18 at 13:38
experimental
gets you the older filesystem TS implementation, which will be removed in the next ABI-breaking release of MSVC.
– T.C.
Nov 22 '18 at 15:30
Hmm, I am not sure now whether my answer is correct after reading yours T.C, nice answer!
– gsamaras
Nov 22 '18 at 11:20
Hmm, I am not sure now whether my answer is correct after reading yours T.C, nice answer!
– gsamaras
Nov 22 '18 at 11:20
I don't know if I'm in a position to determine if using
path()
or the experimental
namspace is more correct than the other. So I won't accept an answer until I get more enlighted within the subjet. They both work however, rendering a slightly different output. Using path()
will render "" around each find, while experimental
namespace will not. The data is still the same though.– bork
Nov 22 '18 at 13:38
I don't know if I'm in a position to determine if using
path()
or the experimental
namspace is more correct than the other. So I won't accept an answer until I get more enlighted within the subjet. They both work however, rendering a slightly different output. Using path()
will render "" around each find, while experimental
namespace will not. The data is still the same though.– bork
Nov 22 '18 at 13:38
experimental
gets you the older filesystem TS implementation, which will be removed in the next ABI-breaking release of MSVC.– T.C.
Nov 22 '18 at 15:30
experimental
gets you the older filesystem TS implementation, which will be removed in the next ABI-breaking release of MSVC.– T.C.
Nov 22 '18 at 15:30
add a comment |
Change this:
namespace fs = std::filesystem;
to this:
namespace fs = std::experimental::filesystem;
because VS 17 uses an experimental version of the filesystem
.
add a comment |
Change this:
namespace fs = std::filesystem;
to this:
namespace fs = std::experimental::filesystem;
because VS 17 uses an experimental version of the filesystem
.
add a comment |
Change this:
namespace fs = std::filesystem;
to this:
namespace fs = std::experimental::filesystem;
because VS 17 uses an experimental version of the filesystem
.
Change this:
namespace fs = std::filesystem;
to this:
namespace fs = std::experimental::filesystem;
because VS 17 uses an experimental version of the filesystem
.
answered Nov 22 '18 at 11:10
gsamarasgsamaras
52.8k25110197
52.8k25110197
add a comment |
add a comment |
For Visual Studio 2017 (15.8 and 15.9 if I'm not mistaken), filesystem
only exposes an experimental version, so use:
namespace fs = std::experimental::filesystem;
add a comment |
For Visual Studio 2017 (15.8 and 15.9 if I'm not mistaken), filesystem
only exposes an experimental version, so use:
namespace fs = std::experimental::filesystem;
add a comment |
For Visual Studio 2017 (15.8 and 15.9 if I'm not mistaken), filesystem
only exposes an experimental version, so use:
namespace fs = std::experimental::filesystem;
For Visual Studio 2017 (15.8 and 15.9 if I'm not mistaken), filesystem
only exposes an experimental version, so use:
namespace fs = std::experimental::filesystem;
answered Nov 22 '18 at 11:10
Matthieu BrucherMatthieu Brucher
17.7k52445
17.7k52445
add a comment |
add a comment |
Use the std::experimental
namespace:
namespace fs = std::experimental::filesystem;
1
Hey Peter, I believe you are right, but I don't see what that answer adds further than my answer and Matthieu's... :/
– gsamaras
Nov 22 '18 at 11:17
Yes you're right. I just tried the sample in vs2017 and posted the answer here. Sorry, I didn't see your answers.
– Peter
Nov 22 '18 at 11:24
add a comment |
Use the std::experimental
namespace:
namespace fs = std::experimental::filesystem;
1
Hey Peter, I believe you are right, but I don't see what that answer adds further than my answer and Matthieu's... :/
– gsamaras
Nov 22 '18 at 11:17
Yes you're right. I just tried the sample in vs2017 and posted the answer here. Sorry, I didn't see your answers.
– Peter
Nov 22 '18 at 11:24
add a comment |
Use the std::experimental
namespace:
namespace fs = std::experimental::filesystem;
Use the std::experimental
namespace:
namespace fs = std::experimental::filesystem;
answered Nov 22 '18 at 11:16
PeterPeter
66618
66618
1
Hey Peter, I believe you are right, but I don't see what that answer adds further than my answer and Matthieu's... :/
– gsamaras
Nov 22 '18 at 11:17
Yes you're right. I just tried the sample in vs2017 and posted the answer here. Sorry, I didn't see your answers.
– Peter
Nov 22 '18 at 11:24
add a comment |
1
Hey Peter, I believe you are right, but I don't see what that answer adds further than my answer and Matthieu's... :/
– gsamaras
Nov 22 '18 at 11:17
Yes you're right. I just tried the sample in vs2017 and posted the answer here. Sorry, I didn't see your answers.
– Peter
Nov 22 '18 at 11:24
1
1
Hey Peter, I believe you are right, but I don't see what that answer adds further than my answer and Matthieu's... :/
– gsamaras
Nov 22 '18 at 11:17
Hey Peter, I believe you are right, but I don't see what that answer adds further than my answer and Matthieu's... :/
– gsamaras
Nov 22 '18 at 11:17
Yes you're right. I just tried the sample in vs2017 and posted the answer here. Sorry, I didn't see your answers.
– Peter
Nov 22 '18 at 11:24
Yes you're right. I just tried the sample in vs2017 and posted the answer here. Sorry, I didn't see your answers.
– Peter
Nov 22 '18 at 11:24
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53429574%2fc-no-operator-matches-these-operands-directory-iterator%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown