C++萬能庫-- 頭文件介紹(包含源代碼)


送給你我:無一事敢馬虎,無一事敢懈怠,心存敬畏之心,不敢得意忘形!

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

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。

 

業精於勤荒於嬉,行成於思毀於隨!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM