gpt4 book ai didi

c++ - 如何在 gcc 8 上使用 std::filesystem?

转载 作者:太空狗 更新时间:2023-10-29 20:33:45 26 4
gpt4 key购买 nike

我已经更新了 gcc 版本,gcc --version 产生以下输出

    gcc (Ubuntu 8.1.0-5ubuntu1~16.04) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

我可以在头文件中包含文件系统而不会出现任何错误

#include<filesystem>

但是当我尝试像下面这样访问命名空间文件系统时,我得到了错误

namespace fs = std::filesystem;

错误信息

error: ‘filesystem’ is not a namespace-name
namespace fs = std::filesystem;

这似乎很奇怪,因为 gcc 8 支持 std::filesystem 并且它在命名空间中不可用,我在访问 std::filesystem 时做错了什么吗?

是的,我用 -std=c++17 构建

最佳答案

将文件系统库作为参数添加到将转发给链接器的编译器。还要确保您使用的是 C++17。 g++ 和 clang++ 都接受这种特殊格式:

--std=c++17 -lstdc++fs

关于c++ - 如何在 gcc 8 上使用 std::filesystem?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53201991/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com