为什么 GCC 似乎没有文件系统标准库?

Why does GCC not seem to have the filesystem standard library?

我遇到了文件系统库的问题,它应该包含在 c++17 编译器中,2 天后我尝试在 raspberry pi 中安装 gcc-7.0.2 但没有成功,它无法识别命令 gcc-7 或 g++-7 甚至 -std=c++17 所以我不得不使用 apt-get install 安装 g++-6 和 gcc-6 无论如何,在安装 6 版本后,编译器包含 c++17。 我使用代码块作为 IDE,我必须添加一个新的编译器并添加选项 -std=c++17 来启用它,但是在主代码中当我包含文件系统库时它说没有这样的文件或目录。

我的问题是,如何正确添加 c++17 编译器及其库(如文件系统)??

GCC v7还是没有实现<filesystem> but it does have the Filesystem Technical Specification which is in <experimental/filesystem>

#include <experimental/filesystem>

// for brevity
namespace fs = std::experimental::filesystem;

int main()
{
    fs::path p = "/path/to/my/file"; // etc...
}

这也适用于 GCC v6

要使用库 link,您需要将 -lstdc++fs 添加到命令行。

注意:当前的技术规范<filesystem>的最终草案之间可能存在一些细微差别,即由标准委员会决定。

注 2: GCC v8 现在使用 -std=c++17 标志实现 <filesystem>

首先你应该看看 C++17 Support in GCC

海湾合作委员会 8

Runtime Library (libstdc++)

  • Improved experimental support for C++17, including the following features:
    • Deduction guides to support class template argument deduction.
    • std::filesystem implementation.
    • std::char_traits<char> and std::char_traits<wchar_t> are usable in constant expressions.
    • std::to_chars and std::from_chars (for integers only, not for floating point types).

来源:https://gcc.gnu.org/gcc-8/changes.html

海湾合作委员会 9

Runtime Library (libstdc++)

  • Improved support for C++17, including:
    • The C++17 implementation is no longer experimental.
    • Parallel algorithms and <execution> (requires Thread Building Blocks 2018 or newer).
    • <memory_resource>.
    • Using the types and functions in <filesystem> does not require linking with -lstdc++fs now.

来源:https://gcc.gnu.org/gcc-9/changes.html