问题
I'm writing a script which deletes old backup files. I've included "filesystem" as I would normally do, but this time, I got this error: "fatal error: filesystem: No such file or directory"
I tried to include "experimental/filesystem" and I set "-lstdc++fs" as GCC flag. Nothing has worked for me.
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
fs::path const directory{ "C:\Test" };
std::vector<fs::directory_entry>::size_type const num_files_to_keep{ 5 };
回答1:
Using CodeBlocks ang GCC 8.0 or above You need to set c++17 compiler option
(I'm using CodeBlock last Nightly build).
Then you must add to the Linker settings options the stdc++fs
library.
And then you must add the #include <filesystem>
directive, from GCC 8.0, and not <experimental/filesystem>
On windows the directory separator is \\
(two backslash).
You need to write:
fs::path const directory { "C:\\Test" };
来源:https://stackoverflow.com/questions/56987678/how-to-fix-fatal-error-filesystem-no-such-file-or-directory-in-codeblocks