std::filesystem' has not been declared after including experimental/filesystem
You use std::filesystem::directory_iterator
. std::filesystem::directory_iterator
and the entire namespace std::filesystem
are declared in the header <filesystem>
.
You haven't included the header <filesystem>
. Instead, you've included <experimental/filesystem>
. This header does not declare std::filesystem::directory_iterator
. Instead, it declares std::experimental::filesystem::directory_iterator
.
You can consistently use either the standard filesystem library, or the experimental filesystem library from the technical specification, but you must not mix them together. If you're targeting C++17, then you should use <filesystem>
.
I will get the error that filesystem: No such file or directory
The ideal solution is to upgrade your compiler to a version that has non-experimental support for C++17. Otherwise use the experimental TS or Boost.
C++ an VS error: experimental/filesystem header providing std::experimental::filesystem is deprecated by Microsoft and will be REMOVED
I had the same problem and then, when I removed the experimental filesystem and added:
#include <filesystem>
namespace fs = std::filesystem;
I would get the error:
namespace “std” has no member “filesystem”
The solution was to go to project properties and do as instructed in the link.
VS2017: E0135 namespace "std" has no member "filesystem"
Using std::experimental::filesystem with g++ 9.3.0
I would use the version of C++ standard in combination with a pre-processor directive to distinguish between them as it the filesystem library has been officially introduced in C++17
#if __cplusplus >= 201703L
#include <filesystem>
namespace fs = std::filesystem;
#else
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#endif
In case this occurs to you with another library in C++17 you can use __has_include
#if __has_include(<some_lib>)
#include <some_lib>
namespace sl = std::some_lib;
#else
#include <experimental/some_lib>
namespace sl = std::experimental::some_lib;
#endif
C++ experimental filesystem library incomplete?
You are confused, because std::experimental::filesystem
(<experimental/filesystem>
) contains the Filesystem TS, not the filesystem additions to C++17 which are found in std::filesystem
(<filesystem>
) if your standard library implements them (although the latter is based on the former).
In the TS there is a std::experimental::filesystem::is_regular_file
free function (which you link to in the question). This free std::filesystem::is_regular_file
also exists in C++17.
However in C++17 the std::filesystem::directory_entry
class also has a member function is_regular_file
.
This member function is absent in the TS version std::experimental::filesystem::directory_entry
.
The TS is not exactly the same as what was then later added to the standard library for C++17.
VS2017: E0135 namespace std has no member filesystem
A couple of options to investigate.
- Check the language standard. You need C++17 or above:
- If your version of visual studio doesn't support
std::filesystem
yet, you can trystd::experimental::filesystem
.
I have the following version and std::filesystem
works (with the C++17 language selection shown above):
Microsoft Visual Studio Community 2017 Preview
Version 15.8.0 Preview 1.1
VisualStudio.15.Preview/15.8.0-pre.1.1+27705.2000
Link errors using filesystem members in C++17
Add the flag -lstdc++fs
:
$ g++-7 test.cpp -std=c++17 -lstdc++fs
gcc 7.2 supports C++17 experimental filesystem
namespace only. I do not know, maybe gcc 7.3 supports std filesystem
namespace already.
Related Topics
Crtp -- Accessing Incomplete Type Members
How Can Duff's Device Code Be Compiled
Eigen::Ref for Concatenating Matrices
Understanding Gsl::Narrow Implementation
When Does a Std::Vector Reallocate Its Memory Array
Reading and Writing a Std::Vector into a File Correctly with Iterators
How to Pass a Vector to Execvp
C++11: "Narrowing Conversion Inside { }" with Modulus
Difference Between Opening a File in Binary VS Text
Getting a List of User Profiles on a Computer in C++ Win32
Visual Studio 2013 Fatal Error C1041 /Fs
Restrict Passed Parameter to a String Literal
Check Char at Current/Given Position in Pdcurses/Ncurses
Troubles with Boost::Spirit::Lex & Whitespace
What Are Consequences of Forcing Qobject as a Parent of Qwidget
Why Do Sin(45) and Cos(45) Give Different Results
How to Tokenize (Words) Classifying Punctuation as Space
How to Design Proper Release of a Boost::Asio Socket or Wrapper Thereof