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;
}







3















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.










share|improve this question































    3















    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.










    share|improve this question



























      3












      3








      3








      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.










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 11:11









      gsamaras

      52.8k25110197




      52.8k25110197










      asked Nov 22 '18 at 11:06









      borkbork

      6463929




      6463929
























          4 Answers
          4






          active

          oldest

          votes


















          3














          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.






          share|improve this answer


























          • 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













          • 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



















          2














          Change this:



          namespace fs = std::filesystem;


          to this:



          namespace fs = std::experimental::filesystem;


          because VS 17 uses an experimental version of the filesystem.






          share|improve this answer































            1














            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;





            share|improve this answer































              1














              Use the std::experimental namespace:



              namespace fs = std::experimental::filesystem;





              share|improve this answer



















              • 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












              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
              });


              }
              });














              draft saved

              draft discarded


















              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









              3














              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.






              share|improve this answer


























              • 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













              • 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
















              3














              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.






              share|improve this answer


























              • 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













              • 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














              3












              3








              3







              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.






              share|improve this answer















              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.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              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 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



















              • 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













              • 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













              2














              Change this:



              namespace fs = std::filesystem;


              to this:



              namespace fs = std::experimental::filesystem;


              because VS 17 uses an experimental version of the filesystem.






              share|improve this answer




























                2














                Change this:



                namespace fs = std::filesystem;


                to this:



                namespace fs = std::experimental::filesystem;


                because VS 17 uses an experimental version of the filesystem.






                share|improve this answer


























                  2












                  2








                  2







                  Change this:



                  namespace fs = std::filesystem;


                  to this:



                  namespace fs = std::experimental::filesystem;


                  because VS 17 uses an experimental version of the filesystem.






                  share|improve this answer













                  Change this:



                  namespace fs = std::filesystem;


                  to this:



                  namespace fs = std::experimental::filesystem;


                  because VS 17 uses an experimental version of the filesystem.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 22 '18 at 11:10









                  gsamarasgsamaras

                  52.8k25110197




                  52.8k25110197























                      1














                      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;





                      share|improve this answer




























                        1














                        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;





                        share|improve this answer


























                          1












                          1








                          1







                          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;





                          share|improve this answer













                          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;






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 22 '18 at 11:10









                          Matthieu BrucherMatthieu Brucher

                          17.7k52445




                          17.7k52445























                              1














                              Use the std::experimental namespace:



                              namespace fs = std::experimental::filesystem;





                              share|improve this answer



















                              • 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














                              Use the std::experimental namespace:



                              namespace fs = std::experimental::filesystem;





                              share|improve this answer



















                              • 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








                              1







                              Use the std::experimental namespace:



                              namespace fs = std::experimental::filesystem;





                              share|improve this answer













                              Use the std::experimental namespace:



                              namespace fs = std::experimental::filesystem;






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              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














                              • 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


















                              draft saved

                              draft discarded




















































                              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.




                              draft saved


                              draft discarded














                              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





















































                              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







                              Popular posts from this blog

                              鏡平學校

                              ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

                              Why https connections are so slow when debugging (stepping over) in Java?