本文介绍了如何在带有-std = c ++ 17的g ++ 6.2.0中包含C ++ 17头文件(可选,任意,string_view,变体)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

std :: optional 在C ++ 17中,以前是 std :: experimental :: optional

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

我尝试使用以下命令编译包含< optional> 的文件:

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

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

(在Bash终端中)。我收到以下错误:

(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

但是我可以#包括< experimental / optional> 很好。

我缺少一些头文件吗?如何包含可选标头?

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

我也不能包含<任何> < string_view> < variant> ,得到相同的错误。

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

推荐答案

您不能。

,这就是标题为何如此的原因

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

如果他们只是在白天为 std :: regex 这样做的话!

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

这篇关于如何在带有-std = c ++ 17的g ++ 6.2.0中包含C ++ 17头文件(可选,任意,string_view,变体)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-27 19:03