how to use std::filesystem on gcc 8?(如何在 gcc 8 上使用 std::filesystem?)
问题描述
我已经更新了 gcc 版本,gcc --version 产生以下输出
I have updated version of gcc, gcc --version produces the following output
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.
我可以在头文件中包含文件系统而不会出现任何错误
i can include filesystem in header file without any error
#include<filesystem>
但是当我尝试像下面那样访问命名空间文件系统时,我得到了错误
But when i try to access the namespace filesystem like below then i get the error
namespace fs = std::filesystem;
错误信息
error: ‘filesystem’ is not a namespace-name
namespace fs = std::filesystem;
这似乎很奇怪,因为 gcc 8 支持 std::filesystem 并且它在命名空间中不可用,我在访问 std::filesystem 时做错了吗?
This seems to be weird since the gcc 8 has support for std::filesystem and it is not available in namespace, am i doing anything wrong in accessing std::filesystem?
是的,我是用 -std=c++17 构建的
and yes i built with -std=c++17
推荐答案
将文件系统库添加为编译器的参数,该编译器将转发到链接器.还要确保您使用的是 C++17.g++ 和 clang++ 都接受这种特殊格式:
Add the filesystem library as an argument to your compiler that will be forwarded to the linker. Also make sure you are using C++17. Both g++ and clang++ accepts this particular format:
--std=c++17 -lstdc++fs
这篇关于如何在 gcc 8 上使用 std::filesystem?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 gcc 8 上使用 std::filesystem?
基础教程推荐
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- CString 到 char* 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
