Mac 查看编译器默认使用C++标准

Mac 查看编译器默认使用的C++标准

C++标准

对应关系

c 复制代码
#include<iostream>
using namespace std;

int main(){
	//__cplusplus这个宏中记录了当前使用的版本
    cout << __cplusplus << endl;
    //C++ pre-C++98: __cplusplus is 1.
    // C++98: __cplusplus is 199711L.
    // C++11: __cplusplus is 201103L.
    // C++14: __cplusplus is 201402L.
    // C++17: __cplusplus is 201703L.
    // C++20: __cplusplus is 202002L.
}

使用指定的C++标准编译

shell 复制代码
g++ -std=c++20 "文件.cpp" -o "目标名.cpp"

想要默认C++标准为指定版本

可以使用别名,将g++指定为g++ -std=c++20
首先打开你的shell配置

shell 复制代码
vim ~/.zshrc

在最下面新增该条

shell 复制代码
alias g++='g++ -std=c++20

更新zsh

shell 复制代码
source ~/.zshrc
相关推荐
And_Ii4 小时前
LCR 168. 丑数
c++
CoderMeijun5 小时前
C++ 时间处理与格式化输出:从 Linux 时间函数到 Timestamp 封装
c++·printf·stringstream·时间处理·clock_gettime
yuanzhengme8 小时前
AI【应用 04】FunASR离线文件转写服务开发指南(实践篇)
人工智能·macos·xcode
tankeven8 小时前
HJ176 【模板】滑动窗口
c++·算法
OxyTheCrack9 小时前
【C++】一文详解C++智能指针自定义删除器(以Redis连接池为例)
c++·redis
whitelbwwww9 小时前
C++基础--类型、函数、作用域、指针、引用、文件
开发语言·c++
leaves falling9 小时前
C/C++ const:修饰变量和指针的区别(和引用底层关系)
c语言·开发语言·c++
tod1139 小时前
深入解析ext2文件系统架构
linux·服务器·c++·文件系统·ext
不想写代码的星星9 小时前
C++ 类型萃取:重生之我在幼儿园修炼类型学
c++
比昨天多敲两行9 小时前
C++11新特性
开发语言·c++