zoukankan      html  css  js  c++  java
  • C++ 中头文件<bits/stdc++.h>的优缺点

    C++ 中头文件<bits/stdc++.h>的优缺点

    一、总结

    一句话总结:

    1、bits/stdc++.h是部分C++中支持的一个几乎万能的头文件,包含所有的可用到的C++库函数,如<istream>/<ostream>/<stack>/<queue>等.
    2、原理是在这个文件中包含了其它的头文件
    // 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

    二、C++ 中头文件<bits/stdc++.h>的优缺点

    转自或参考:C++ 中头文件<bits/stdc++.h>的优缺点
    https://www.cnblogs.com/qinduanyinghua/p/11338028.html

    在编程竞赛中,我们常见一个头文件:

    #include <bits/stdc++.h>

      发现它是部分C++中支持的一个几乎万能的头文件,包含所有的可用到的C++库函数,如<istream>/<ostream>/<stack>/<queue>.

    该头文件的详细内容如下:

      1 // C++ includes used for precompiling -*- C++ -*-
      2  
      3 // Copyright (C) 2003-2013 Free Software Foundation, Inc.
      4 //
      5 // This file is part of the GNU ISO C++ Library.  This library is free
      6 // software; you can redistribute it and/or modify it under the
      7 // terms of the GNU General Public License as published by the
      8 // Free Software Foundation; either version 3, or (at your option)
      9 // any later version.
     10  
     11 // This library is distributed in the hope that it will be useful,
     12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14 // GNU General Public License for more details.
     15  
     16 // Under Section 7 of GPL version 3, you are granted additional
     17 // permissions described in the GCC Runtime Library Exception, version
     18 // 3.1, as published by the Free Software Foundation.
     19  
     20 // You should have received a copy of the GNU General Public License and
     21 // a copy of the GCC Runtime Library Exception along with this program;
     22 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
     23 // <Licenses - GNU Project - Free Software Foundation>.
     24  
     25 /** @file stdc++.h
     26  *  This is an implementation file for a precompiled header.
     27  */
     28  
     29 // 17.4.1.2 Headers
     30  
     31 // C
     32 #ifndef _GLIBCXX_NO_ASSERT
     33 #include <cassert>
     34 #endif
     35 #include <cctype>
     36 #include <cerrno>
     37 #include <cfloat>
     38 #include <ciso646>
     39 #include <climits>
     40 #include <clocale>
     41 #include <cmath>
     42 #include <csetjmp>
     43 #include <csignal>
     44 #include <cstdarg>
     45 #include <cstddef>
     46 #include <cstdio>
     47 #include <cstdlib>
     48 #include <cstring>
     49 #include <ctime>
     50  
     51 #if __cplusplus >= 201103L
     52 #include <ccomplex>
     53 #include <cfenv>
     54 #include <cinttypes>
     55 #include <cstdalign>
     56 #include <cstdbool>
     57 #include <cstdint>
     58 #include <ctgmath>
     59 #include <cwchar>
     60 #include <cwctype>
     61 #endif
     62  
     63 // C++
     64 #include <algorithm>
     65 #include <bitset>
     66 #include <complex>
     67 #include <deque>
     68 #include <exception>
     69 #include <fstream>
     70 #include <functional>
     71 #include <iomanip>
     72 #include <ios>
     73 #include <iosfwd>
     74 #include <iostream>
     75 #include <istream>
     76 #include <iterator>
     77 #include <limits>
     78 #include <list>
     79 #include <locale>
     80 #include <map>
     81 #include <memory>
     82 #include <new>
     83 #include <numeric>
     84 #include <ostream>
     85 #include <queue>
     86 #include <set>
     87 #include <sstream>
     88 #include <stack>
     89 #include <stdexcept>
     90 #include <streambuf>
     91 #include <string>
     92 #include <typeinfo>
     93 #include <utility>
     94 #include <valarray>
     95 #include <vector>
     96  
     97 #if __cplusplus >= 201103L
     98 #include <array>
     99 #include <atomic>
    100 #include <chrono>
    101 #include <condition_variable>
    102 #include <forward_list>
    103 #include <future>
    104 #include <initializer_list>
    105 #include <mutex>
    106 #include <random>
    107 #include <ratio>
    108 #include <regex>
    109 #include <scoped_allocator>
    110 #include <system_error>
    111 #include <thread>
    112 #include <tuple>
    113 #include <typeindex>
    114 #include <type_traits>
    115 #include <unordered_map>
    116 #include <unordered_set>
    117 #endif

      在编程竞赛中,使用这个头文件是一个好的想法,特别是当你在选择头文件时想减少时间,我们更加专注于找到算法解决问题而不是软件工程。而从软件工程的视角,我们最好最小化包含头文件,如果你包含了一些你可能不会用到的头文件,就会增加不必要的编译时间和程序大小。

     bits/stdc++的缺点

    • bits/stdc++.h 不是GNU C++库的标准头文件,所以如果你在一些编译器(除了GCC)上编译你的代码,可能会失败,比如MSVC没有这个头文件。
    • 使用它会包含很多不必要的东西,并且会增加编译时间
    • 这个头文件不是C++标准的一部分,所以是不可移植的,应该尽量避免。
    • 尽管标准中有一些通用的头文件,但还是应该避免使用它来代替特定的头文件,因为编译器在每次编译转换单元时都实际地读取并解析每个包含的头文件(包括递归包含的头文件)。

    bits/stdc++的优点

    • 在比赛中,使用这个文件是一个好主意,当你想减少时间浪费在做选择的时候;特别是当你的排名对时间很敏感的时候。
    • 这还减少了编写所有必要头文件的所有杂务。
    • 你不必为使用的每个函数都记住GNU c++的所有STL。
     
  • 相关阅读:
    Java 读取某个目录下所有文件、文件夹
    poi根据excel模板导出Excel
    UML关系(泛化,实现,依赖,关联(聚合,组合))
    使用Git下载Hadoop的到本地Eclipse开发环境
    maven command to create your application
    Roo中的@Version
    oracle 给用户赋表空间
    hiberante 二级缓存设置
    procedure
    Oracle综合数据库管理命令集
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/13023208.html
Copyright © 2011-2022 走看看