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>
, 得到同样的错误。
最佳答案
关于c++ - 如何使用 -std=c++17(可选、任意、string_view、变体)在 g++ 6.2.0 中包含 C++ 17 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43889414/