关于c++:C头文件-bitsstdch-是啥

4次阅读

共计 3205 个字符,预计需要花费 9 分钟才能阅读完成。

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

欢送拜访我的博客:http://blog.duhbb.com/

嘿嘿, 当前写 leetcode 的话, 本地间接就援用这个文件, 还是很不便的; 然而因为不可移植以减少编译工夫等, 墙裂倡议不要在生产环境应用.

引言

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

#include <bits/stdc++.h>

而后我就有点奇怪了, 以前如同没有遇到过呀, 而后这个 C++ 头文件也比拟特地, 是以 .h 结尾的, 于是乎打算一探到底.

它是 C++ 中反对的一个简直万能的头文件, 简直蕴含所有的可用到的 C++ 库函数. 当前写代码就能够间接援用这一个头文件了, 不须要在写一大堆 vector, string, map, stack 等等

应用办法

#include <bits/stdc++.h>

int main() {
    // write code here
    return 0
}

头文件的内容

// 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++.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/

正文完
 0