c++ - std::gcd 无法在 g++ 5.4.0 中编译 - 'gcd' 不是 'std' 的成员

标签 c++ g++ std c++17 greatest-common-divisor

环境:

  • Ubuntu 16.04 64 位
  • g++ 版本 5.4.0

这是代码:

#include <numeric>
...
auto g = std::gcd(10, 4);
...

我在编译命令中打开了-std=c++17选项:

g++ -m64 -std=c++17   -c -g -w -MMD -MP -MF "build/Debug/GNU-Linux/main.o.d" -o build/Debug/GNU-Linux/main.o main.cpp

然后我得到了错误:

error: 'gcd' is not a member of 'std'

来自this webpage , std::gcd 是从 C++17 开始引入的。

来自this webpage ,我的g++版本支持C++17。

但是为什么还是有错误呢?相同的代码在 Visual Studio 2017 中编译时不会出现任何错误。

最佳答案

std::gcd 仅从 GCC 7.1 开始可用。

来自Table 1.5. C++ 2017 Implementation Status

enter image description here

查看多个一致性查看器 GCC versions .

关于c++ - std::gcd 无法在 g++ 5.4.0 中编译 - 'gcd' 不是 'std' 的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54746702/

相关文章:

c++ - 用于通信的二进制缓冲区,C++

c++ - 什么是函数 __tcf_0? (在使用 gprof 和 g++ 时看到)

C++:创建一个包含两个可执行文件的 makefile? C++

c++ - 哈希函数无法正常工作

c++ - Visual Studio 2013 代码分析卡在 native 代码上

c++ - 链接程序时是否需要重复编译标志?

c++ - 在 C++ Lambda 表达式中,为什么人们更喜欢按值捕获而不是作为参数传递?

c++ - Autoscan autoconf 生成的配置脚本无法在 C++ 代码中找到 cmath 函数

c++ - 引用计数类的库实现

c++ - std::cout、ostream等获取输出流