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

原文地址: 【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/

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值