How to include C++ 17 headers with g++ 6.2.0 with -std=c++17 (optional, any, string_view, variant)(如何在 g++ 6.2.0 和 -std=c++17 中包含 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
但我可以 #include <experimental/optional> 就好了.
我是否缺少一些头文件?如何包含 optional 标头?
Am I missing some header files? How can I include the optional header?
我也不能包含 <any>、<string_view> 或 <variant>,得到同样的错误.
I also can't include <any>, <string_view> or <variant>, getting the same error.
推荐答案
你不能.
GCC 6.2 对 C++17 的支持是实验性的,它从字面上看,为什么标题是这样排列的.
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.
https://gcc.gnu.org/projects/cxx-status.html#cxx1z
这篇关于如何在 g++ 6.2.0 和 -std=c++17 中包含 C++ 17 标头(可选、任意、string_view、变体)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 g++ 6.2.0 和 -std=c++17 中包含 C++ 17 标头(可选
基础教程推荐
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- CString 到 char* 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
