作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
最近想用from_chars
来自 C++17。
看了 http://en.cppreference.com/w/cpp/utility/from_chars并在此页面上找到了该代码:
#include <iostream>
#include <charconv>
#include <array>
int main()
{
std::array<char, 10> str{"42"};
int result;
std::from_chars(str.data(), str.data()+str.size(), result);
std::cout << result;
}
<source>:2:10: fatal error: 'charconv' file not found
#include <charconv>
^~~~~~~~~~
1 error generated.
Compiler returned: 1
最佳答案
根据 GCC's libstdc++ status page ,仅从 GCC-8.1 开始支持此 header 。您可以通过检测来避免使用此 header :
#if __has_include(<charconv>)
#include <charconv>
#else
/* implement some fallback */
#endif
或者只是更新你的编译器。此
godbolt example确认标题存在于 GCC-8.1 中。
stdlibc++
默认情况下。您需要更新 GCC 或切换到 Clang 的
libc++
经过:
clang++ -std=c++17 -stdlib=libc++ main.cpp
关于c++ - fatal error : 'charconv' file not found in clang 6. 0 与 -std=c++17,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49639808/
我已经编写了一些使用 c++17 的 charconv 的代码,我可以用 g++ 9 编译得很好。即使我在我的 CMakeLists.txt 中将 std 设置为 c++17,cmake 坚持使用不支
最近想用from_chars来自 C++17。 看了 http://en.cppreference.com/w/cpp/utility/from_chars并在此页面上找到了该代码: #include
我是一名优秀的程序员,十分优秀!