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:

bash 复制代码
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. 添加内容

在文件中添加以下内容:

cpp 复制代码
#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++,例如:

bash 复制代码
/opt/homebrew/bin/g++-14 -o test test.cpp
相关推荐
551只玄猫2 小时前
【数学建模 matlab 实验报告1】
开发语言·数学建模·matlab·课程设计·实验报告
史蒂芬_丁2 小时前
Qt, C++数据类型扩展问题
数据库·c++·qt
6Hzlia2 小时前
【Hot 100 刷题计划】 LeetCode 118. 杨辉三角 | C++ 动态规划题解
c++·leetcode·动态规划
三道渊3 小时前
C语言:文件I/O
c语言·开发语言·数据结构·c++
hnlgzb3 小时前
安卓app kotlin语法,Hilt是什么东西?
android·开发语言·kotlin
没用的阿_吉3 小时前
windows10 Qt5.15.14 msvc2019 编译部署
开发语言·qt
聊聊MES那点事3 小时前
JavaScript图表控件AG Charts使用教程:使用AG Charts React实时更新柱状图
开发语言·javascript·react.js·图表控件
ywf12153 小时前
Go基础之环境搭建
开发语言·后端·golang
是有头发的程序猿4 小时前
用Open Claw接口做1688选品、价格监控、货源对比
开发语言·c++·人工智能
斯班奇的好朋友阿法法4 小时前
离线ollama导入Qwen3.5-9B.Q8_0.gguf模型
开发语言·前端·javascript