Notes on #include<bits/stdc++.h>

Notes on #include<bits/stdc++.h>

When looking at C/C++ competition questions, I often see #include<bits/stdc++.h>. What does that mean?

Some people call <bits/stdc++.h> a universal header file. Its
advantages:
  1. Save time during the competition.
  2. Reduce the workload of writing all necessary header files.
  3. For every function used, there is no need to remember all the STL of GNU C++.
Disadvantages:
  1. Standard header files that do not belong to the GNU C++ library may fail in some cases.
  2. Using it will contain a lot of unnecessary stuff and increase compilation time.
  3. This header file is not part of the C++ standard and therefore is not portable and should be avoided.
  4. The compiler must actually read and analyze each included header file every time it compiles a translation unit, and the use of such header files should be reduced.

#include is a preprocessing directive in C and C++ languages ​​that tells the compiler to include the contents of a header file into the current source code file during compilation. This allows you to use functions, variables, macros, etc. defined in the header file in the current source code file.
<bits/stdc++.h> It is a special header file that contains the header files of most standard C and C++ libraries. It can easily introduce multiple libraries at one time and simplify the code writing process. For C++, in this header file, the standard libraries usually included include:
<iostream>: used for input and output operations.
<vector>: Provides the implementation of dynamic arrays (vectors).
<string>: Process string operations.
<algorithm>: Contains various algorithms, such as sorting, search, etc.
<cmath>: Contains mathematical functions, such as numerical calculations, trigonometric functions, etc.
<queue>: Implements a queue (first in, first out) data structure.
<stack>: Implements a stack (last in, first out) data structure.
<map>: A data structure that implements key-value pair storage.

... The method of checking the header files of C and C++ libraries contained in <bits/stdc++.h> included with DevC++ will be given later.

Using the <bits/stdc++.h> header file can save you the tedious process of introducing various standard libraries, because it has already included all commonly used standard library header files. It should be noted that <bits/stdc++.h> is not a standard C++ header file. Its use is feasible in some compilers (such as the GCC compiler), but it is not guaranteed to work properly in all compilers. Therefore, when writing portable C++ code, it is recommended to use standard header files and introduce the required library header files as needed to avoid compatibility issues on different compilers.

DevC++ can use <bits/stdc++.h>.

If you installed the Windows version of DevC++, you can see stdc++
in the installation path Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\x86_64-w64-mingw32\32\bits .h This is the <bits/stdc++.h> version of DevC++. It is a text file, which can be opened with "Notepad".


[C/C++ uses include to introduce header files that can include paths, if the header files are located in the same directory as the current source file, no path is required.
Generally, it is recommended to use angle brackets < > to introduce system-level header files, such as #include <bits/stdc++.h>. At this time, the compiler will look for the predefined system path to locate the header file; and use double quotes " " to Introduce user-defined header files, such as #include "mypath/myheader.h"]

The following is an example of DevC++ using the <bits/stdc++.h> header file. Implementation:  input 4 integers a, b, c, d in sequence, and output them in reverse order, that is, output d, c, b, a in sequence. number.

#include <bits/stdc++.h>
using namespace std;
int a,b,c,d;
int main() {
	cin>>a>>b>>c>>d;
	cout<<d<<' '<<c<<' '<<b<<' '<<a;

	return 0;
}

OK! 

Guess you like

Origin blog.csdn.net/cnds123/article/details/132553346