c/c++万能头文件#include <bits/stdc++.h>

好奇万能头文件#include <bits/stdc++.h>怎么能够如此强大

直到打开文件发现原来。。。

// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
```cpp #include <bits/stdc++.h> ``` 这个头文件 **在某些编译环境下是“正确”的**,但需要明确以下几点: --- ### ✅ 1. 它是什么? - `#include <bits/stdc++.h>` 是 GNU C++ 编译器(g++)中的一个 **非标准的万能头文件**。 - 它包含了 C++ 标准库中几乎所有常用的头文件,例如: - `<iostream>` - `<vector>` - `<string>` - `<algorithm>` - `<map>` - `<set>` - `<queue>` - `<cmath>` 等等。 --- ### ✅ 2. 是否“正确”? | 场景 | 是否可用 | 说明 | |------|----------|------| | **OJ 在线评测系统(如PTA、洛谷、Codeforces、LeetCode等)** | ✅ 可用 | 这些平台通常使用 g++ 编译,支持该头文件 | | **标准 C++ 程序 / 跨平台项目 / 工业代码** | ❌ 不推荐 | 非 ISO C++ 标准,不可移植 | | **考试环境(如蓝桥杯、PAT、NOI系列)** | ✅ 一般允许 | 特别是国内 OJ 常默认开启 g++ | > 所以:**在竞赛和刷题场景下,它是“事实上的正确”;但在工程开发中应避免使用。** --- ### ⚠️ 3. 为什么不标准? - `bits/` 是 GCC 内部实现细节目录,不属于公共接口。 - `stdc++.h` 并不在 C++ 标准规定中。 - 其他编译器(如 MSVC、Clang without libstdc++)可能不支持。 --- ### ✅ 4. 使用建议 #### ✔️ 推荐用于: - 算法竞赛 - 快速原型验证 - 刷题写代码时节省时间 ```cpp #include <bits/stdc++.h> using namespace std; int main() { vector<int> v = {1, 2, 3}; sort(v.begin(), v.end()); cout << "Hello Algorithm!" << endl; return 0; } ``` #### ❌ 不推荐用于: - 实际软件开发 - 需要跨平台或长期维护的项目 - 学习阶段(不利于理解具体头文件作用) --- ### ✅ 5. 替代方案(标准写法) 如果你希望写出可移植、规范的代码,请显式包含所需头文件: ```cpp #include <iostream> #include <vector> #include <algorithm> #include <string> #include <map> #include <set> #include <queue> #include <cmath> #include <cstdio> using namespace std; ``` --- ### 🔚 总结 ```text #include <bits/stdc++.h> → 在 g++ 和在线判题系统中是“合法且常用”的; → 不是 ISO C++ 标准的一部分,属于 GCC 扩展; → 刷题可以用,生产环境不要用。 ``` ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值