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.
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>
?
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>
.
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
Include lots of unused headers will drastically increase build time! Add only needed files
You could simply create a pre-compiled-header file for yourself of often included to speed up builds. It was popular last millennium.
You can try:
#ifndef ALL_H_FILES
#define ALL_H_FILES
#include <iostream>
#include <vector>
#include <list>
//include other libraries
#endif
On your main file, you can: #include "ALL_H_FILES.h"
Rejoice. C++23 shall save you effort of including everything: You can just do:
import std; //imports everything in std library
import std.compat; //brings c library to global namespace
Although you may need to wait for a year or three for compilers to support it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.