c++ - 如何使用 -std=c++17(可选、任意、string_view、变体)在 g++ 6.2.0 中包含 C++ 17 header

标签 c++ include g++ header-files c++17

std::optional在 C++ 17 中,它是 std::experimental::optional之前。

我尝试编译一个包含 <optional> 的文件, 使用命令:

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

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

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

但我可以#include <experimental/optional>就好了。

我是否缺少一些头文件?如何包含 optional标题?

我也不能包含 <any> , <string_view><variant> , 得到同样的错误。

最佳答案

你不能。

GCC 6.2's support for C++17 is experimental ,这就是标题如此排列的原因。

要是他们当年为 std::regex 这样做就好了!这是一份礼物。

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

关于c++ - 如何使用 -std=c++17(可选、任意、string_view、变体)在 g++ 6.2.0 中包含 C++ 17 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43889414/

相关文章:

ubuntu - 在 Ubuntu 中很难将数学和 GSL 联系起来

c++ - strncpy 和 strcat 没有按照我认为的方式工作 C++

php - 第二次包含后变量为空

c++ 添加两个 bool 数组

C++ 无法访问抽象类 vector 的元素?

C++ --- getline 和 cinignore() 删除输出字符串中的第一个字符

C++ 模板性能包含模型和内联模型

php - 从可以与 include() 一起使用的 MySQL 数据库中获取数据

c++ - 使用 boost python 和 python 3.2 的 Hello world

c++ - boost - thread.join() 停止 ui