c++ - 尚未声明 std::numbers - Windows 上的 GCC 11.2
问题描述
我在我的 Windows 10 机器上安装了 GCC 11.2.0(来自这里:https ://winlibs.com/ )。我已将环境变量路径更新为C:\MinGW\bin
gcc version 11.2.0 (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders)
我正在使用带有 C/C++ 扩展的 VSCode,该扩展配置为使用正确的编译器路径。
我想使用一个 C++20 功能,它是
std::numbers::sqrt2
我仍然收到一个错误,告诉我它不知道 std::numbers
[Running] cd "c:\Users\XX\XX\" && g++
main.cpp -o main && "c:\Users\XX\XX\"main
main.cpp: In function 'double sin_x_plus_cos_sqrt2_times_x(double)':
main.cpp:15:41: error: 'std::numbers' has not been declared
15 | return std::sin(x) + std::cos( std::numbers::sqrt2 * x );
|
我已经添加了标题#include <numbers>
我错过了什么?
解决方案
此版本 gcc 的默认 c++ 标准版本是 C++17。看到这个:https ://godbolt.org/z/4Pjzd5r7s
利用
g++ main.cpp -o main -std=c++20
强制 C++20
gcc 中对 C++20 有一些支持,但将其设为默认标准还为时过早。
推荐阅读
- java - 使用 th:object 保存所有对象
- arduino - ESP8266-01 如何使用电阻将 GPIO 接地,如下图所示
- angular - Angular 获得 30 多个结果
- javascript - 我如何在 swagger/nodejs 中检查不记名令牌
- node.js - 如何以编程方式运行和停止运行 Artillery.io?
- excel - 如何使用集合为用户表单中的下拉列表提供选项 - Excel VBA
- swift - 我们可以在 swift 包管理器中使用协调器模式吗?
- java - 2021-02-22T00:00:00 的日期模式格式
- python - TypeError: index_queryset() 得到了一个意外的关键字参数“使用”
- python - 在 AWS Batch 作业中发送参数的编程方式