文件系统: 没有这样的文件或目录

使用 CentOs 7.1,GCC 版本6.1.0(GCC) 我收到这个错误:

fatal error: filesystem: No such file or directory

在这条线上

#include <filesystem>

编译

g++ main.cpp -o main -std=c++17

问题出在哪里?

103715 次浏览

It seems you have to include <filesystem> like this:

#include <experimental/filesystem>

Don't forget to add -lstdc++fs as a GCC flag!

Here is the proof: Coliru

If that doesn't work, then that probably means that you don't have filesystem in your configuration.

Also, as @MartinR. pointed out, the experimental is no longer needed in GCC 8+.