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
相关推荐
梦醒沉醉8 分钟前
C++和标准库速成(五)——C风格的数组、std::array、std::vector、std::pair和std::optional
c++
写一本我们家的书44 分钟前
Qt MainWindow简单例子(文本编辑)
开发语言·qt
ん贤1 小时前
【数据结构】栈与队列:基础 + 竞赛高频算法实操(含代码实现)
java·数据结构·c++·算法
JCBP_1 小时前
C语言经典代码题
c语言·开发语言·汇编·vscode·算法
萧萧玉树1 小时前
设计模式-单一职责
开发语言·c++·设计模式
java1234_小锋1 小时前
一周学会Flask3 Python Web开发-SQLAlchemy添加数据操作-班级模块
开发语言·前端·python·flask·flask3
forestsea1 小时前
Java 8 Stream API:传统实现和流式编程的范式对比
java·开发语言
多多*2 小时前
Spring设计模式 八股速记 高层模块底层模块 依赖倒置原则 开闭原则 接口隔离原则
java·开发语言·数据库·macos·github·objective-c·cocoa
小林熬夜学编程2 小时前
【高并发内存池】第一弹---深入解析内存池:项目介绍、原理及设计定长内存池全攻略
linux·服务器·c语言·开发语言·c++·算法
郭涤生2 小时前
Chapter 2:auto_《Effective Modern C++》notes
开发语言·c++·笔记