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
相关推荐
专注VB编程开发20年14 小时前
CSS 的命名方式像是 PowerShell 的动词-名词结构,缺乏面向对象的层级关系
开发语言·后端·rust
古译汉书14 小时前
嵌入式铁头山羊stm32-ADC实现定时器触发的注入序列的单通道转换-Day26
开发语言·数据结构·stm32·单片机·嵌入式硬件·算法
UnnamedOrange15 小时前
ROS2 配置 linter 的代码格式化工具为 clang-format
c++·cmake
Dobby_0515 小时前
【面试题】C++系列(一)
c++·面经
计算机毕业设计木哥15 小时前
计算机毕设选题:基于Python+Django的B站数据分析系统的设计与实现【源码+文档+调试】
java·开发语言·后端·python·spark·django·课程设计
一拳一个呆瓜15 小时前
【MFC】对话框节点属性:Language(语言)
c++·mfc
陈陈爱java15 小时前
Spring八股文
开发语言·javascript·数据库
歪歪10015 小时前
qt creator新手入门以及结合sql server数据库开发
c语言·开发语言·后端·qt·数据库开发
@大迁世界16 小时前
用 popover=“hint“ 打造友好的 HTML 提示:一招让界面更“懂人”
开发语言·前端·javascript·css·html
星哥说事16 小时前
Python自学12 — 函数和模块
开发语言·python