• 【C++】头文件 bits/stdc++.h 是啥?


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

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

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

    引言

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

    #include <bits/stdc++.h>
    
    • 1

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

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

    使用方法

    #include <bits/stdc++.h>
    
    int main() {
        // write code here
        return 0
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    头文件的内容

    // 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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117

    优点与缺点

    来源: 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/

  • 相关阅读:
    JavaScript-Object.is()和‘===’ ‘==’比较运算符的区别
    @PostConstruct详解
    【算法笔记】三种背包问题——背包 DP
    Python实操:内存管理与优化策略
    Ajax fetch navigator.sendBeacon 三个的区别
    WifiCountryCode&信道
    低代码不是银弹,为什么很多程序员讨厌低代码?
    Kafka3.x核心速查手册二、客户端使用篇-3、消息序列化机制
    「C++」简单模拟
    PostgreSQL serial类型
  • 原文地址:https://blog.csdn.net/ea8d1n3/article/details/125481671