原文地址: 【C++】头文件 bits/stdc++.h 是啥?

欢迎访问我的博客:http://blog.duhbb.com/

嘿嘿, 以后写 leetcode 的话, 本地直接就引用这个文件, 还是很方便的;但是由于不可移植以增加编译时间等, 墙裂建议不要在生产环境使用.

引言

最近看别人的 C++ 代码, 发现了这么一个头文件:

#include <bits/stdc++.h>

然后我就有点奇怪了, 以前好像没有遇到过呀, 然后这个 C++ 头文件也比较特别, 是以 .h 结尾的, 于是乎打算一探究竟.

它是 C++ 中支持的一个几乎万能的头文件, 几乎包含所有的可用到的 C++ 库函数. 以后写代码就可以直接引用这一个头文件了, 不需要在写一大堆 vector, string, map, stack 等等

使用方法

#include <bits/stdc++.h>int main() {// write code herereturn 0
}

头文件的内容

// C++ includes used for precompiling -*- C++ -*-// Copyright (C) 2003-2013 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
// <Licenses - GNU Project - Free Software Foundation>./** @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>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

优点与缺点

来源: bits/stdc++.h in C++

bits/stdc++ 的缺点

  1. bits/stdc++.h 是 GNU C++ 库的非标准头文件. 因此, 如果您尝试使用 GCC 以外的其他编译器编译代码, 它可能会失败;例如,MSVC 没有此标头.
  2. 使用它会包含很多不必要的东西并增加编译时间.
  3. 此头文件不是 C++ 标准的一部分, 因此不可移植, 应避免使用.
  4. 此外, 即使标准中有一些包罗万象的标头, 您也希望避免使用它来代替特定标头, 因为编译器必须每次都实际读取并解析每个包含的标头 (包括递归包含的标头) 编译单元.

bits/stdc++的优点

  1. 在比赛中, 当你想减少浪费在做家务上的时间时, 使用这个文件是个好主意;尤其是当您的排名对时间敏感时.
  2. 这也减少了编写所有必要的头文件的所有琐事.
  3. 您不必为使用的每个函数记住所有 GNU C++ 的 STL.

原文地址: 【C++】头文件 bits/stdc++.h 是啥?

欢迎访问我的博客:http://blog.duhbb.com/

【C++】头文件 bits/stdc++.h 是啥?相关推荐

  1. C++预编译头文件 bits/stdc++.h

    有时候会看到别人包含这样的头文件: #include "bits/stdc++.h" 这个头文件中有很多预先包含的头文件,内容如下: // C++ includes used fo ...

  2. 高级c++头文件bits/stdc++.h

    用这种方法声明头文件只需两行代码 #include<bits/stdc++.h> using namespace std; 这个头文件包含以下等等C++中包含的所有头文件: #includ ...

  3. C++万能头文件(bits/stdc++.h)

    先说一句 C++万能头文件,并不是所有场合都能用,比如说POJ. 我曾在POJ提交过程序,编译错误.就是因为用了万能头文件. 意思就是,不认识<bits/stdc++.h>. 因为,万能头 ...

  4. VS C++万能头文件bits/stdc++.h的配置

    万能头文件:#include<bits/stdc++.h> 路径:C:\Program Files\Microsoft Visual Studio\2022\Community\VC\To ...

  5. 【环境配置】macOS的Xcode中使用C++万能头文件bits/stdc++.h

    启动终端 cd /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c ...

  6. std.h对应linux头文件,bits/stdc++.h头文件介绍(包含源代码)

    注:转自http://blog.csdn.net/charles_dong2/article/details/56909347,同为本人写的,有部分修改. 之前在一个小OJ上刷题时发现有人是这么写的: ...

  7. 浅说万能头<bits/stdc++.h>

    #include<bits/stdc++.h>包含了C和C++的绝大多数头文件,像iostream.cmath.algorithm.iomanip.string之类的,这意味着我们不再需要 ...

  8. Cfree之万能头函数bits\stdc++.h的添加和注意事项

    实现步骤 一.创建一个.txt文件,把下面的代码复制进去 // C++ includes used for precompiling -*- C++ -*-// Copyright (C) 2003- ...

  9. VScode找不到C++万能头文件<bits/stdc++.h>解决办法

    VScode找不到C++万能头文件<bits/stdc++.h>解决办法 一.万能头文件介绍 万能头文件<bits/stdc++> 中包含了 C++中大部分头文件,在大部分做题 ...

最新文章

  1. Opengl-面剔除(一种优化方式)
  2. 遇到虚拟系统内存问题怎么办?Hypervisor帮你除bug
  3. MySQL——EXPLAIN和执行计划
  4. java 内存映射文件 主要应用_VC++中使用内存映射文件处理大文件(3)
  5. C++预处理程序指令
  6. MySQL 创建索引
  7. 4.PHP核心技术与最佳实践 --- 数据库(队列)
  8. 部分转 Java读取ini配置
  9. Codeforces Round #358 (Div. 2) Alyona and Strings
  10. 二分类变量相关性分析spss_SPSS教程 | 两个有序分类变量的相关分析及SPSS操作
  11. 用c语言编程解决数学实际问题,运用C语言解决爱因斯坦的数学题
  12. 抖音小店开通及保证金详情;抖音小店商品上架详细流程。丨国仁网络资讯
  13. xapp1025仿真
  14. uni-app初学步骤教程:
  15. 腾讯云微服务引擎 TSE 11月产品动态
  16. Android Studio如何查看自己创建的SQLite数据库
  17. 配置 SNAT 和NAT
  18. Mysql 时区修改问题(冬令时夏令时)
  19. 立即关闭计算机的命令,谁有或者知道电脑立即关机的bat命令条令?
  20. XNA开发一个2D的小游戏

热门文章

  1. 电商项目4:全栈之前端
  2. 计算机桌面图标简笔画,简笔画大全电脑版
  3. android串口通信
  4. Linux防火墙禁止ping的方法
  5. html里h标签的三个作用,H标签是什么?怎么用?
  6. 国产14纳米芯片的推出,或代表着7纳米国产有了希望
  7. CSDN APP发布富文本、MarkDown编辑器;社区动态支持快转……【2022.1.19】
  8. 【MySQL数据库设计与应用(六)】存储程序(存储过程,存储函数,触发器,事件)
  9. CorelDRAW中的三维线条表现方法
  10. C语言爱心扩展加思路