简要回答:可以,但取决于你安装的编译器版本,而不是 CentOS 系统本身是否“支持”。
CentOS 只是一个 Linux 发行版,是否能用 C++ 最新标准(如 C++20 / C++23),取决于你安装的 编译器(gcc / clang)版本。
CentOS 系统内核和 glibc 不直接限制 C++ 语言特性,只要编译器支持即可。
✅ 解决方案:
yum install centos-release-scl
yum install devtoolset-11
scl enable devtoolset-11 bash
✅ 或安装更新版本:
dnf install gcc-toolset-12
你也可以手动安装 LLVM / Clang:
示例:
clang++ -std=c++20 main.cpp
#include <iostream>
int main() {
auto sum = [](auto... x) { return (x + ...); };
std::cout << sum(1, 2, 3, 4) << std::endl;
}
编译:
g++ -std=c++20 test.cpp -o test
✅ CentOS 可以运行 C++ 最新标准
⚠️ 但通常需要升级 gcc / clang
❌ 不能用系统自带的老 gcc 直接写 C++20/23
如果你愿意,我可以: