300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 【C++】头文件 bits/stdc++.h 是啥?

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

时间:2023-12-05 22:36:20

相关推荐

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

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

欢迎访问我的博客:/

嘿嘿, 以后写 leetcode 的话, 本地直接就引用这个文件, 还是很方便的;但是由于不可移植以增加编译时间等, 墙裂建议不要在生产环境使用.

引言

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

#include <bits/stdc++.h>

然后我就有点奇怪了, 以前好像没有遇到过呀, 然后这个 C++ 头文件也比较特别, 是以.h结尾的, 于是乎打算一探究竟.

它是 C++ 中支持的一个几乎万能的头文件, 几乎包含所有的可用到的 C++ 库函数. 以后写代码就可以直接引用这一个头文件了, 不需要在写一大堆 vector, string, map, stack 等等

使用方法

#include <bits/stdc++.h>int main() {// write code herereturn 0}

头文件的内容

// C++ includes used for precompiling -*- C++ -*-// Copyright (C) - 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 >= 03L#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 >= 03L#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++ 的缺点

bits/stdc++.h 是 GNU C++ 库的非标准头文件. 因此, 如果您尝试使用 GCC 以外的其他编译器编译代码, 它可能会失败;例如,MSVC 没有此标头.使用它会包含很多不必要的东西并增加编译时间.此头文件不是 C++ 标准的一部分, 因此不可移植, 应避免使用.此外, 即使标准中有一些包罗万象的标头, 您也希望避免使用它来代替特定标头, 因为编译器必须每次都实际读取并解析每个包含的标头 (包括递归包含的标头) 编译单元.

bits/stdc++的优点

在比赛中, 当你想减少浪费在做家务上的时间时, 使用这个文件是个好主意;尤其是当您的排名对时间敏感时.这也减少了编写所有必要的头文件的所有琐事.您不必为使用的每个函数记住所有 GNU C++ 的 STL.

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

欢迎访问我的博客:/

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。