C++ 中头文件<bits/stdc++.h>的优缺点
在编程竞赛中,我们常见一个头文件:
- #include <bits/stdc++.h>
发现它是部分C++中支持的一个几乎万能的头文件,包含所有的可用到的C++库函数,如<istream>/<ostream>/<stack>/<queue>.
该头文件的详细内容如下:
- // 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++的缺点
- bits/stdc++.h 不是GNU C++库的标准头文件,所以如果你在一些编译器(除了GCC)上编译你的代码,可能会失败,比如MSVC没有这个头文件。
- 使用它会包含很多不必要的东西,并且会增加编译时间
- 这个头文件不是C++标准的一部分,所以是不可移植的,应该尽量避免。
- 尽管标准中有一些通用的头文件,但还是应该避免使用它来代替特定的头文件,因为编译器在每次编译转换单元时都实际地读取并解析每个包含的头文件(包括递归包含的头文件)。
bits/stdc++的优点
- 在比赛中,使用这个文件是一个好主意,当你想减少时间浪费在做选择的时候;特别是当你的排名对时间很敏感的时候。
- 这还减少了编写所有必要头文件的所有杂务。
- 你不必为使用的每个函数都记住GNU c++的所有STL。
C++ 中头文件<bits/stdc++.h>的优缺点的更多相关文章
- C++万能头文件<bits/stdc++.h>的内容与优缺点
最近发现了一个C++的头文件bits/stdc++.h,听说这是一个几乎包含了所有C++库函数的头文件,就想更深入的了解一下,下面是头文件内容 // C++ includes used for pre ...
- C++标准库头文件<bits/stdc++.h>
在使用GNU GCC Compiler的时候,你可以包含一个头文件<bits/stdc++.h>,便可以使用C++中的各种标准库,而不用一个一个包含进来. 这在acm比赛中是一种常用的做法 ...
- 高级c++头文件bits/stdc++.h
用这种方法声明头文件只需两行代码 #include<bits/stdc++.h> using namespace std; 这个头文件包含以下等等C++中包含的所有头文件: #includ ...
- 2.头文件<bits/stdc++.h>
用这种方法声明头文件只需两行代码 #include<bits/stdc++.h> using namespace std; 这个头文件包含以下等等C++中包含的所有头文件: #inclu ...
- C++头文件<bits/stdc++.h>
在刷题时,总发现有的只写一行头文件 #include <bits/stdc++.h> . 查阅资料后,才知道原来:#include<bits/stdc++.h>包含了目前c++ ...
- 万能pb_ds头文件—bits/extc++.h
c++中自带了一些非常强大却鲜为人知的功能库—pd_ds库 里面含有红黑树(rb_tree),哈希表(gp_hash_table),可持久化平衡树(rope)等超强数据结构 但是有一件非常令人头痛的事 ...
- 为VisualStudio2017添加bits/stdc++.h
在算法编程中经常有人只写一个头文件"bits/stdc++.h" 其实这个是很多头文件的集合,写了它后相当于包含了所有常用的C++头文件,可是需要注意的是并不是所有的OJ系统都支持 ...
- C/C++ 引入头文件时 #include<***.h> 与 #include"***.h" 区别
两种情况区分: 1.#include <> 编译器只会去系统文件目录中查找,找不到就报错. 2.#include " " 编译器会先在用户目录中查找,再到编译器设定的 ...
- Visual Studio 中使用万能头文件 #include <bits/stdc++.h>
最近开始使用VS,之前用的DEV C++软件可直接使用 #include <bits/stdc++.h> ,但VS中并没有,为了使用方便,可直接在VS中添加此头文件,方法如下: 1.在安 ...
随机推荐
- String2LongUtil
public class String2LongUtil { /** * String类型转换成date类型 * strTime: 要转换的string类型的时间, * formatType: 要转换 ...
- Zabbix通过SNMP监控HP Gen10服务器的硬件
http://www.zmzblog.com/monitor/zabbix-how-to-monitoring-hp-gen10-server-hardware.html
- leetcode 53. Maximum Subarray 、152. Maximum Product Subarray
53. Maximum Subarray 之前的值小于0就不加了.dp[i]表示以i结尾当前的最大和,所以需要用一个变量保存最大值. 动态规划的方法: class Solution { public: ...
- Git-Runoob:Git 安装配置
ylbtech-Git-Runoob:Git 安装配置 1.返回顶部 1. Git 安装配置 在使用Git前我们需要先安装 Git.Git 目前支持 Linux/Unix.Solaris.Mac和 W ...
- sqlalchemy.exc.InvalidRequestError: Table 'run_result' is already defined for this MetaData instance
临时解决办法: 在models文件导入db后,加上如下代码: db.metadata.clear() 但解决问题的根本之处还是在于找到,为何会声明了2次类的定义呢? 解析: table 'roles_ ...
- fiddler之请求过滤(Filters)
开启fiddler后,会监听所有的请求,在大多数情况下,我们只需要监听部分请求,此时可以使用Filters功能去控制. 界面显示如下: 默认情况下过滤是未开启的,需要勾选“user filters”进 ...
- OPEN SQL:插入、删除、修改语法
1. UPDATE 用于实现对数据据的更新操作,语法如下: UPDATE <dbtab> set f1...fn (where <condition>). UPDATE < ...
- 中国MOOC_零基础学Java语言_第4周 循环控制_2念整数
2 念整数(5分) 题目内容: 你的程序要读入一个整数,范围是[-100000,100000].然后,用汉语拼音将这个整数的每一位输出出来. 如输入1234,则输出: yi er san si 注意, ...
- 【SSH】---【Struts2、Hibernate5、Spring4集成开发】【SSH框架整合笔记】
Struts2.Hibernate5.Spring4集成开发步骤: 一.导入Jar包(基本的大致有41个,根据实际项目的需求自己添加) antlr-2.7.7.jar aopalliance.jar ...
- Java多线程学习——join方法的使用
join在线程里面意味着“插队”,哪个线程调用join代表哪个线程插队先执行——但是插谁的队是有讲究了,不是说你可以插到队头去做第一个吃螃蟹的人,而是插到在当前运行线程的前面,比如系统目前运行线程A, ...