macOS 中,默认的 Clang 编译器和 Homebrew 安装的 GCC 都不包含 bits/stdc++.h 文件

在 macOS 中,默认的 Clang 编译器和 Homebrew 安装的 GCC 都不包含 bits/stdc++.h 文件,因为它是一个 非标准 的头文件,主要由 MinGW 和某些 Linux 平台的 GCC 提供。

解决方案 : 手动创建 bits/stdc++.h

1. 创建文件夹和文件

在你的 GCC 标准头文件目录中创建 bits/stdc++.h:

mkdir -p /opt/homebrew/Cellar/gcc/14.2.0_1/include/c++/14.2.0/x86_64-apple-darwin22/bits
nano /opt/homebrew/Cellar/gcc/14.2.0_1/include/c++/14.2.0/x86_64-apple-darwin22/bits/stdc++.h

2. 添加内容

在文件中添加以下内容:

#ifndef _GLIBCXX_STD_BITS_STDCPP_H
#define _GLIBCXX_STD_BITS_STDCPP_H

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <climits>
#include <utility>
#include <numeric>
#include <cassert>

#endif

3. 验证

编译时使用 Homebrew 安装的 g++,例如:

/opt/homebrew/bin/g++-14 -o test test.cpp
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值