如何解决“严重错误:文件系统:没有这样的文件或目录"在Code :: Blocks中? [英] How to fix "fatal error: filesystem: No such file or directory" in Code::Blocks?
问题描述
我正在编写一个删除旧备份文件的脚本.我已经像平常一样包含了文件系统",但是这次,我得到了这个错误:致命错误:文件系统:没有这样的文件或目录"
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"
我尝试包括"experimental/filesystem",并将"-lstdc ++ fs"设置为GCC标志.什么都没有为我工作.
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 };
推荐答案
使用CodeBlocks ang GCC 8.0或更高版本您需要设置c ++ 17编译器选项
(我在上次Nightly版本中使用CodeBlock).
然后,必须将stdc++fs
库添加到链接器设置选项.
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.
然后必须添加GCC 8.0中的#include <filesystem>
指令,而不是<experimental/filesystem>
在Windows上,目录分隔符为\\
(两个反斜杠).
您需要编写:
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" };
这篇关于如何解决“严重错误:文件系统:没有这样的文件或目录"在Code :: Blocks中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!