How to include all of the C++ Standard Library at once?
Solution 1
On some compilers, including <bits/stdc++.h>
might do what you're looking for.
Note however that it makes your code nonportable (it may not work on other compilers, or even different versions of the same compiler). This is ok in some cases.
More info about why doing this might not be a good idea: Why should I not #include <bits/stdc++.h>
?
Solution 2
You can use:
#include<bits/stdc++.h>
as even suggested by everyone.But it is not a standard header file. The disadvantages of it are that it is
- increases the compilation time.(As it includes all the header files together)
- uses an internal non-standard header file of the GNU C++ library, and so will not compile in MSVC, XCode, and many other compilers
Solution 3
Is there a singular preprocessor that I can add to my project to do both of these? Or do I just have to include both?
No there isn't and that's intentional. The standard library implementation should have a minimum of inter dependencies for the implemented components.
You should always specify the #include
statements for the std
components you use explicitly.
And don't be tricked by the infamous #include <bits/stdc++.h>
.
Solution 4
Include lots of unused headers will drastically increase build time! Add only needed files
Solution 5
You could simply create a pre-compiled-header file for yourself of often included to speed up builds. It was popular last millennium.
Callat
I'm your avg nerd and new programmer I'm out to learn new software so that when the machines take over the world, I can take over the machine. "Knowledge is not enough, one must apply" Bruce Lee
Updated on July 02, 2020Comments
-
Callat almost 4 years
I am working on a class project using vectors and linked lists. But in C++ in order to apply them I need to have the following code in my header.
#include<list> #include<vector>
I know that both of these are a part of the standard template library. So I'd like to do a single
#include<StandardTemplateLibrary>
to save lines. But everywhere I look I don't see a singular command to add to my code and I've tried cstdlib, stdlib, cstdlib.h and none of them contain the keywords I need.
Is there a singular preprocessor that I can add to my project to do both of these? Or do I just have to include both? If you can refer me to source to read as well that'd be greatly appreciated.
-
Bart Friederichs about 8 yearsOut of curiosity: why is this intentional?
-
πάντα ῥεῖ about 8 years@BartFriederichs To minimize dependencies.
-
Chiel about 8 yearsThis is a useless answer for the OP if you don't explain why it is intentional and why you should ALWAYS specify the includes for what you use explicitly and why the OP shouldn't be tricked by the infamous include. You are fully right, but if you don't explain why, it is hard to learn anything from this post.
-
πάντα ῥεῖ about 8 years@Chiel The disadvantages of
#include <bits/stdc++>
are well explained in the linked post.