Reputation: 87
I'm struggling with the filesystem library in Visual Studio Code. I just can't understand why it doesn't work. I'm simply using an example code from that library:
#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.path() << '\n';
fs::remove_all("sandbox");
}
And I get the following error:
'filesystem' is not a namespace-name
I've seen a few threads about this, but they all describe creating makefiles. I don't really want to do this just to learn there was some fundamental error that the makefile doesn't solve. Is there a way to make it simply work with some command? This thread: Visual Studio Code: how to add arguments for g++ compiler? mentions a line
g++ -g -o debug main.cpp -std=c++17
so I assume it IS possible. But when I type it, I get a ton of errors and nothing compiles.
For some reason, Visual Studio 2019 has no issues - I had some problems initially, but it was simply solved by changing the C++ standard to C++ 17. After that, everything builds and works. In Visual Studio Code I already have the C++ 17 on, so why it doesn't work in this case?
Upvotes: 1
Views: 3617
Reputation: 555
Mate, I had the same issue. The solution to this is to change the C++ version to the latest one under solution properties > C++ and change it from the default C++ version (most likely C++ 14) to the latest on or anything above C++ 17.
Upvotes: 2
Reputation: 87
thank you all for your input. I'm done with this problem, although without any actual solution. MinGW is my biggest suspect, since:
My GCC version, where the compilation doesn't work, is g++.exe (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
Also, on Linux, it works when I type the command like this:
g++ main.cpp -std=c++17 -lstdc++fs -o main
Upvotes: 0