gpt4 book ai didi

c++ - 为什么不#include

转载 作者:行者123 更新时间:2023-12-02 10:56:23 24 4
gpt4 key购买 nike

我用我的代码发布了一个问题,其唯一的#include指令如下:

#include <bits/stdc++.h>

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

为什么?

最佳答案

在Stack Overflow上看到包括<bits/stdc++.h>似乎越来越常见,也许是本学年在国家类(class)中新增的内容。

我想这样就隐约地给出了优势:

  • 您只需要写一个#include
  • 您无需查找
  • 中所有内容的标准 header

    不幸的是,这是一个懒惰的黑客,直接命名GCC内部 header ,而不是单独的标准 header (如 <string><iostream><vector>)。它破坏了便携性并养成了可怕的习惯。

    缺点包括:
  • 它可能仅在该编译器上起作用
  • 您不知道使用它时会做什么,因为它的内容不是由标准
  • 设置的
  • 即使只是将编译器升级到自己的下一个版本,也可能会破坏程序
  • 每个标准 header 都必须与源代码一起进行解析和编译,这很慢,并且在某些编译设置下会导致可执行文件体积庞大。

  • 不要这样做!

    更多信息:
  • #include <bits/stdc++.h> with visual studio does not compile
  • How does #include <bits/stdc++.h> work in C++?

  • Quora为何不好的示例:
  • Is it good practice to use #include <bits/stdc++.h> in programming contests instead of listing a lot of includes?
  • 关于c++ - 为什么不#include <bits/stdc++。h>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62812376/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com