【发布时间】:2020-11-03 12:39:42
【问题描述】:
我想尝试使用三路比较运算符 (<=>) 但是...
代码:
#include <compare>
int main(){
.
.
.
}
命令:
g++ -std=c++2a compare.cpp
输出:
compare.cpp:10:10: fatal error: compare: No such file or directory
10 | #include <compare>
| ^~~~~~~~~
compilation terminated.
我找不到任何解决方案来修复此错误。我正在使用 g++ 9.3.0。
g++ 还不支持<compare> 吗?
如果有,如何使用 g++ 修复此错误?
或者如果没有,请教我另一种使用<compare>的方法,不用g++。
【问题讨论】:
-
您使用的是什么版本的 GCC?至少试试GCC 10。
-
这里是功能列表及其编译器支持en.cppreference.com/w/cpp/compiler_support - 我建议您查阅它
-
欢迎来到 StackOverflow!默认情况下,g++ 不一定使用最新版本的标准,因此为旧版本编写的代码会继续以可预测的方式编译。因此,您可能需要传递一个开关以使其使用更高版本,例如
-std=c++20(或 GCC 9 中的-std=c++2a)。 -
感谢您的建议。我用过g++ 9.3.0,现在安装试试gcc10。
-
阅读this