c++ 类如何作为头文件
<bits / stdc ++。h>头文件 (<bits/stdc++.h> header file)
It’s the header file that includes every header files, i.e., links every header file to our program.
它是包含每个头文件的头文件,即,将每个头文件链接到我们的程序。
The following code chunk is enough to include every header file needed to be linked in the program.
以下代码块足以包含程序中需要链接的每个头文件。
#include <bits/stdc++.h>
Using namespace std;
Like you don’t need to put your time on writing & finding each header file to be mentioned, instead, just add this piece of code chunk.
就像您不需要花时间编写和查找要提及的每个头文件一样,只需添加这段代码即可。
It’s true that including <bits/stdc++.h>, makes the program size larger and increase the complexity time. Also it’s not part of standard library and can only be used in gcc compiler. Other compilers like MSVC(Microsoft Visual C++) don’t have this header.
的确,包含<bits / stdc ++。h>会使程序更大,并增加复杂性。 而且它不是标准库的一部分,只能在gcc编译器中使用。 其他编译器(例如MSVC(Microsoft Visual C ++))没有此标头。
Though <bits/stdc++.h> has such pitfalls, we are not at all bothered by this, since our only focus is on competitive coding context, where we are only concerned about run time complexity, not compile time. Also gcc is used everywhere. Thus using <bits/stdc++.h> is a very efficient coding style for solving interview coding problems.
尽管<bits / stdc ++。h>有这样的陷阱,但我们一点也不为之困扰,因为我们只关注竞争性的编码上下文,在这里我们只关注运行时的复杂性,而不关注编译时间。 gcc也随处可见。 因此,使用<bits / stdc ++。h>是解决面试编码问题的非常有效的编码方式。
One more thing can be very tricky is when we have functional problems to solve. There may be case we have a functional problem, where we need to write the function only & rest of the code is already given (can’t be modified). In such case, we may need to use STL, but so such header file is included in the given code for STL. In such case, it might seem that, we can’t use STL here & we need to take any other way, which is not at all efficient. If you think so, wait a minute!!!
还有一件很棘手的事情是,当我们要解决功能问题时。 在某些情况下,我们可能会遇到功能上的问题,我们只需要编写函数,而其余的代码已经给出(无法修改)。 在这种情况下,我们可能需要使用STL,但是这样的头文件包含在STL的给定代码中。 在这种情况下,似乎我们不能在这里使用STL,我们需要采取其他任何方式,但这根本没有效率。 如果您这样认为,请稍等!!!
You can add #include <bits/stdc++.h> anywhere in the code, since it’s an ANCI MACRO. That’s why just write #include <bits/stdc++.h> before where you start using STL. (Before the function). That’s all.
您可以在代码中的任何位置添加#include <bits / stdc ++。h> ,因为它是ANCI MACRO。 因此,只需在开始使用STL之前编写#include <bits / stdc ++。h> 。 (功能之前)。 就这样。
For example check all my codes (Radib Kar’s articles), as I use it everywhere!!
例如,检查我的所有代码( Radib Kar的文章 ),因为我到处都在使用它!
翻译自: https://www.includehelp.com/cpp-tutorial/bits-std-h-as-header-file-in-cpp.aspx
c++ 类如何作为头文件