为什么我不应该#include< bits / stdc ++。h&gt ;? [英] Why should I not #include <bits/stdc++.h>?

查看:3464
本文介绍了为什么我不应该#include< bits / stdc ++。h&gt ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对我的代码发布了一个问题,其中只有 #include 指令如下:

  #include< bits / stdc ++。h> 

我的老师告诉我这样做,但在评论部分我被告知我不应该



为什么?

解决方案

< bits / stdc ++。h> 似乎是Stack Overflow上越来越常见的东西,也许是在当前学年新增加到国家课程中的东西。



我想象的优点是这样含糊的:




  • 你只需要写一个 include

  • 您不需要查找
  • 中包含的标准标题


不幸的是,这是一个懒惰的黑客,直接命名一个GCC内部头文件,而不是像< string> < iostream> < vector>



缺点包括:





  • 你不知道在使用它时它会做什么,因为它的内容不是由标准设置的

  • 即使只是将您的编译器升级到自己的下一个版本也可能会破坏您的程序

  • 每个标准标头都必须与您的源代码一起解析和编译,可在特定编辑设置下执行。


b $ b




详细信息:





Quora为什么不好的示例:




I posted a question with my code whose only #include directive was the following:

#include <bits/stdc++.h>

My teacher told me to do this, but in the comments section I was informed that I shouldn't.

Why?

解决方案

Including <bits/stdc++.h> appears to be an increasingly common thing to see on Stack Overflow, perhaps something newly added to a national curriculum in the current academic year.

I imagine the advantages are vaguely given thus:

  • You only need write one #include line
  • You do not need to look up which standard header everything is in

Unfortunately, this is a lazy hack, naming a GCC internal header directly instead of individual standard headers like <string>, <iostream> and <vector>. It ruins portability and fosters terrible habits.

The disadvantages include:

  • It will probably only work on that compiler
  • You have no idea what it'll do when you use it, because its contents are not set by a standard
  • Even just upgrading your compiler to its own next version may break your program
  • Every single standard header must be parsed and compiled along with your source code, which is slow and results in a bulky executable under certain compilation settings

Don't do it!


More information:

Example of why Quora is bad:

这篇关于为什么我不应该#include&lt; bits / stdc ++。h&gt ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆