How to fix “fatal error: filesystem: No such file or directory” in Code::Blocks?

孤街醉人 提交于 2020-01-17 00:37:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!