【C++】万能头文件 <bits/stdc++.h> 的用法和优缺点

【C++】万能头文件 <bits/stdc++.h> 的用法和优缺点C 万能头文件 bits stdc h 的用法和优缺点文章目录 C 万能头文件 bits stdc h 的用法和优缺点一 使用方法二 头文件的内容三 VS 中如何使用四 优点与缺点 最近在参考别人的代码时 发现了这么一个头文件 在 C 中引用很广泛 然后查了以下 总结一下 include bits stdc h 它是 C 中支持的一个几乎万能的头文件 几乎包含所有的可用到的 C 库函数 以后写代码就可以直接引用这一个头文件了 不需要在写一大堆 vecto bits

【C++】万能头文件 bits/stdc++.h 的用法和优缺点


  最近在参考别人的代码时,发现了这么一个头文件,在C++中引用很广泛。然后查了以下,总结一下。

#include  
      

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

一、使用方法

#include  
      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 // 
     
       . 
      / @file stdc++.h * This is an implementation file for a precompiled header. */ // 17.4.1.2 Headers // C #ifndef _GLIBCXX_NO_ASSERT #include  
       #endif #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #if __cplusplus >= L #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #endif // C++ #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #if __cplusplus >= L #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #include  
       #endif 

三、VS 中如何使用

  新建一个bits文件夹,里面新建一个名叫stdc++.h的头文件,然后把上面的stdc++.h源文件复制进去保存。

  在这个路径下Microsoft Visual Studio2017\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include新建bits文件夹;然后在bits文件夹新建stdc++.h文件。

image-20210624160518031


四、优点与缺点

  说了这么多对于这个头文件的看法,自己也有了更加深刻的认识,那么它真的是程序员梦寐以求的头文件嘛?

  答案是:并不是。它包含大量不需要的库的头文件,更适合在在线 OJ 比赛中使用,不过在国内 OJ 中,POJ、HDU 不支持这个函数,其他国外的 OJ,还有台湾的 OJ 都支持,CF,Topcoder也都支持。然而,在具体的软件工程的开发中,应该减少包含
,控制编译时间和代码大小。

  优点:

  1、在竞赛中节约时间

  2、减少了编写所有必要头文件的工作量

  3、对于使用的每个函数,不用记住GNU C++的所有STL

  缺点:

  1、不属于GNU C++库的标准头文件,在部分情况下可能会失败

  2、使用它将包含许多不必要的东西,并增加编译时间

  3、这个头文件不是C++标准的一部分,因此是不可移植的,应该避免

  4、编译器每次编译翻译单元时都必须实际读取和分析每个包含的头文件,应该减少这类头文件的使用


  参考文章:

  在 OSX 中安装 GNU GCC 以及使用 bits/stdc++.h 标头档与 Policy-Based Data Structure

  在 C++ 中的

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/206321.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月19日 下午3:58
下一篇 2026年3月19日 下午3:59


相关推荐

  • 智慧生活 | DeepSeek应用指南系列2:揭秘几个DeepSeek常用技巧

    智慧生活 | DeepSeek应用指南系列2:揭秘几个DeepSeek常用技巧

    2026年3月16日
    3
  • ASP.NET 状态服务 及 session丢失问题解决方案总结

    ASP.NET 状态服务 及 session丢失问题解决方案总结原文地址:http://www.cnblogs.com/weixing/archive/2009/09/08/session.html十分感谢作者这篇文章ASP.NET2.0系统时,在程序中做删除或创建文件操作时,出现session丢失问题。采用了如下方法:1、asp.netSession的实现:asp.net的Session是基于HttpModule技术做的

    2022年7月15日
    13
  • 站内信_淘宝站内信在哪里看

    站内信_淘宝站内信在哪里看http://daihaixiang.blog.163.com/blog/static/3830134201111155381735/如果一个网站到了百万级的用户量了,那我不得不膜拜该网站和网站经营

    2022年8月5日
    8
  • TCP-IP详解:Nagle算法

    TCP-IP详解:Nagle算法SmallPacketP 在使用一些协议通讯的时候 比如 Telnet 会有一个字节字节的发送的情景 每次发送一个字节的有用数据 就会产生 41 个字节长的分组 20 个字节的 IPHeader 和 20 个字节的 TCPHeader 这就导致了 1 个字节的有用信息要浪费掉 40 个字节的头部信息 这是一笔巨大的字节开销 而且这种 Smallpacket 在广域网上会增加拥塞的出现

    2026年3月18日
    1
  • 继电器驱动电路(各种单片机、CD4013触发器驱动电路图)

    继电器驱动电路(各种单片机、CD4013触发器驱动电路图)继电器工作原理详解(附3种驱动电路图)2019-09-1216:10继电器继电器是一种电子控制器件,它具有控制系统(又称输入回路)和被控制系统(又称输出回路),通常应用于自动控制电路中,它实际上是用较小的电流去控制较大电流的一种“自动开关”。故在电路中起着自动调节、安全保护、转换电路等作用。继电器的继电特性继电器的输入信号x从零连续增加达到衔铁开始吸合时的动作值xx,继电器的输出信号立刻从y=0跳跃y=ym,即常开触点从断到通。一旦触点闭合,输入量x继续增大,输出信号.

    2022年6月24日
    31
  • centos 7 开启docker的2375端口

    centos 7 开启docker的2375端口首先在Centos7下安装docker,然后修改配置文件信息,运行命令vim/usr/lib/systemd/system/docker.service在配置信息中找到ExecStart=/usr/bin/dockerd-Hfd://–containerd=/run/containerd/containerd.sock-Htcp://0.0.0.0:23…

    2022年5月18日
    215

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号