zoukankan      html  css  js  c++  java
  • C++万能库--<bits/stdc++.h>头文件介绍(包含源代码)

    送给你我:无一事敢马虎,无一事敢懈怠,心存敬畏之心,不敢得意忘形!

    ---------------------------------------------------------------------------------------------

    C++库全解:http://www.cplusplus.com/reference/

    编程中经常由于头文件不全导致编译不通过,通过查找发现C/C++有一个万能库

    #include <bits/stdc++.h>
    

    它是基本是C++中支持的一个几乎万能的头文件,包含所有的可用到的C++库函数,如<istream>/<ostream>/<stack>/<queue>。这样做题的时候直接敲上它,岂不是很方便!!!

    不过值得注意的是:目前POJ还不支持<bits/stdc++.h>(G++、C++都不支持)。HDU部分支持(G++支持,C++不支持)

    下面是<bits/stdc++.h>的源代码(IDE为Dev-C++ 5.11),该头文件的详细内容如下:

    // 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。

    业精于勤荒于嬉,行成于思毁于随!

    若有恒,何必三更起五更眠;最无益,莫过一日曝十日寒。
  • 相关阅读:
    hibernate mysql写入中文乱码 解决
    Java中List Set Map 是否有序等总结
    DDL之操作表
    日常学习链接
    NullPointerException异常的原因及java异常??
    ora-01033:oracle initialization or shutdown in progress 解决方法
    多线程概念
    Myeclipse优化篇
    面试中经常会被问到的70个问题
    Notes from Data Guard
  • 原文地址:https://www.cnblogs.com/sjbin/p/14467202.html
Copyright © 2011-2022 走看看