为什么我不应该#include <bits/stdc++.h>? [英] Why should I not #include <bits/stdc++.h>?
问题描述
我用我的代码发布了一个问题,其唯一的 #include
指令如下:
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.
为什么?
推荐答案
In包括
似乎是 Stack Overflow 上越来越常见的东西,也许是新添加的东西本学年的国家课程.
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:
- 你只需要写一行
#include
- 您无需查找所有内容所在的标准标题
不幸的是,这是一个懒惰的黑客,直接命名 GCC 内部标头而不是像
、
和 这样的单个标准标头<向量>
.它破坏了便携性并养成了糟糕的习惯.
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.
缺点包括:
- 它可能只适用于那个编译器
- 当你使用它时,你不知道它会做什么,因为它的内容不是由标准设置的
- 即使只是将您的编译器升级到它自己的下一个版本也可能会破坏您的程序
- 每个标准头文件都必须与源代码一起解析和编译,这很慢,并且在某些编译设置下会导致可执行文件庞大
不要这样做!
更多信息:
Quora 不好的例子:
Example of why Quora is bad:
这篇关于为什么我不应该#include <bits/stdc++.h>?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!