Search code examples
c++includefilesystemsvisual-studio-2019

when I try and use std::filesystem in vs 2019 I get an error


I am using Microsoft Visual Studio 2019, and whenever I type std::filesystem there's a red bar under "filesystem", with the messages

namespace "std" has no member "filesystem"

and

name followed by '::' must be a class or namespace name

when I don't have "::" in front of it and when I do respectively.

I have included filesystem so I don't see why it doesn't work.

I hope I provided enough information, if not just ask in the comments. if you can't help me with that, maybe you could help me find an alternative to std::filesystem::recursive_directory_iterator.


Solution

  • The filesystem library was added in C++17 and VS2019 starts in C++14 mode by default.

    • Open Project\<project name> Properties
    • Select Configuration Properties\General
    • To the right, there is a field named C++ Standard, select one of these:
      • ISO C++17 Standard (/std:c++17)
      • Preview - Features from the latest C++ working draft (/std:c++latest)

    Then #include <filesystem> and you should be good to go.