std optional: No such file or directory

混江龙づ霸主 提交于 2020-05-14 17:35:11

问题


I tried to compile the following program with different compilers (including gcc 6.1) :

#include <optional>
int main()
{
    std::optional<int> o1;
}

Output is

main.cpp:1:20: fatal error: optional: No such file or directory #include optional

This is even true for the examples given here: http://en.cppreference.com/w/cpp/utility/optional/optional

Any clues why?


回答1:


std::optional will be part of the C++17 standard, but if you want to use before then you will have to use std::experimental::optional instead, available in the header <experimental/optional>.




回答2:


It is in experimental (TS):

#include <experimental/optional>

example:

http://coliru.stacked-crooked.com/a/09ab8d1e51680a79

#include <experimental/optional>
#include <iostream>
int main()
{
    std::experimental::optional<int> o1;
}


来源:https://stackoverflow.com/questions/38253971/std-optional-no-such-file-or-directory

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