本文介绍了如何在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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 07:21