在 Debian 中查看 C++ 版本,一般可以从 编译器版本 和 C++ 标准版本 两个角度来看。
g++ --version
或
g++ -v
示例输出:
g++ (Debian 12.2.0-14) 12.2.0
说明:
12.2.0 是 GCC 编译器版本clang++ --version
#include <iostream>
int main() {
std::cout << __cplusplus << std::endl;
return 0;
}
编译并运行:
g++ test.cpp -o test
./test
输出含义:
| 输出值 | C++ 标准 |
|---|---|
| 199711 | C++98 |
| 201103 | C++11 |
| 201402 | C++14 |
| 201703 | C++17 |
| 202002 | C++20 |
⚠️ 默认不指定标准时,Debian 的 g++ 通常使用 GNU 扩展版本(如 201703L)
g++ test.cpp -std=c++17 -o test
可选项:
-std=c++11-std=c++14-std=c++17-std=c++20ls /usr/bin/g++*
或
dpkg -l | grep g++
update-alternatives --list g++
如果你是想:
可以告诉我你的具体需求,我可以给你更针对性的命令。