- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
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/
假设我们有一个 string_view 和另一个 string_view,它是第一个 string_view 的子集: using namespace std; // just to shorten
我正在使用一个使用 boost::string_view 的 boost 库。但是,我想在我的代码中使用 std::string_view。 问:在这两者之间进行转换的最佳方式是什么? 目前我正在使用
std::string_view::remove_prefix() 和 std::string_view::remove_suffix() 都是 c 中的 constexpr 成员函数++17;但是,
我已经从 Bjarne Stroustrup 的 A Tour of C++ 中复制代码来测试字符串 View ,但我不断收到错误: error: no matching function for c
除了 std::string_view 方法之外,std::string_view 是否比 char* 有任何优势? 如果没有使用 string_view 的方法,是否有任何理由将 char* 重构为
我有这个循环: for (const std::string_view resource : resources) { ... } 由此资源被定义为 inline const std::string_
我有这个循环: for (const std::string_view resource : resources) { ... } 由此资源被定义为 inline const std::string_
而一个 span可以从一个范围构建,一个 string_view不能从一系列字符构造。 因此,例如,需要以下代码: // assume chars_span is a span of chars st
void Foo1(string_view view) { ... } string str = "one two three"; Foo1("one two three"); // Implicit
我有一个字符串,其中包含用 , 字符分隔的数字序列。为了将序列中的值读入数组,我创建了以下 GCC 10 拒绝编译的代码: #include #include #include #include
我在使用 Boost 1.70 时发现了一个相当令人费解的问题,有时 boost::string_view 似乎指向另一个字符串。 这是创建 boost::string_view 的函数调用,如下所示
在以下场景中使用 std::string_view: struct A : public std::exception{ A (const char* c) : v_(c){} con
我正在尝试尽可能多地使用 std::string_view 来包装 C 字符串,但是,每当我正在包装的 C 字符串被动态分配时,我都依赖于此图案: char *cs = get_c_string();
我读了The most elegant way to iterate the words of a string并享受答案的简洁性。现在我想对 string_view 做同样的事情。问题是,strin
我有以下代码: #include class Foo { public: Foo(std::string_view) {} }; 当我这样做时,一切都可以正常编译(使用 clang v8,C
根据一篇文章(here 和 there),这段代码是一个错误的免费示例: #include #include #include int main() { std::string s = "H
string_view 是 C++ 库基础 TS(N3921) 中的一项提议功能,添加到 C++17 据我所知,它是一种代表某种字符串“概念”的类型,它是任何类型的容器的 View ,可以将可视内容存
考虑以下代码: #include #include int main() { std::optional opt { "abc" }; std::cout { std::stri
在 std::string_view 上匹配正则表达式工作正常。但是当我返回匹配的子字符串时,它们会因为某种原因而消失。 std::string_view 参数在函数作用域结束时被销毁,但它指向的内存
This reference指出第二个示例产生了一个悬空指针。如何在第二个表达式中创建悬挂指针而不是在第一个表达式中? std::string_view good("a string literal"
我是一名优秀的程序员,十分优秀!