Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 message

error: ‘filesystem’ is not a namespace-name
 namespace fs = 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?

and yes i built with -std=c++17

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
888 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...