How to include C++ 17 headers with g++ 6.2.0 with -std=c++17 (optional, any, string_view, variant)

我与影子孤独终老i 提交于 2019-11-28 07:43:08

问题


std::optional is in C++ 17, where it was std::experimental::optional before.

I tried compiling a file which included <optional>, with the command:

g++ -std=c++17 <filename>.cpp

(in the Bash terminal). I get the following error:

<filename>.cpp:5:20 fatal error: optional: No such file or directory
 #include <optional>
                    ^
compilation terminated

But I can #include <experimental/optional> just fine.

Am I missing some header files? How can I include the optional header?

I also can't include <any>, <string_view> or <variant>, getting the same error.


回答1:


You can't.

GCC 6.2's support for C++17 is experimental, which is literally why the headers are arranged like this.

If only they'd done this for std::regex back in the day! It's a gift.

https://gcc.gnu.org/projects/cxx-status.html#cxx1z



来源:https://stackoverflow.com/questions/43889414/how-to-include-c-17-headers-with-g-6-2-0-with-std-c17-optional-any-str

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!