Razib
Razib

Reputation: 11163

Shortcut of Importing/Including All Library in C++

In java we can import all class from a package using '*' like - java.lang.*.

While coding in C++ we imports multiple library like this -

#include<cstdio>
#include<iostream>
.....

Is there any shortcut/way in C++ to include all these library using a single statement/line?
Thanks

Upvotes: 1

Views: 11308

Answers (5)

Archi Shaw
Archi Shaw

Reputation: 1

#include <bits/stdc++.h>

you can use this header, it will import all C++ libs for your program.

Upvotes: 0

Thiago Souza
Thiago Souza

Reputation: 1191

You can use this library:

#include<bits/stdc++.h>

This library includes every library you need. Using this, you can delete (or comment) all the others library declarations.

See more here: How does #include bits/stdc++.h work in C++?

Upvotes: 4

bialpio
bialpio

Reputation: 1024

You might also want to take a look at precompiled headers, it should reduce the number of includes in the source files if there is something that you include everywhere.

Upvotes: 1

Thomas Matthews
Thomas Matthews

Reputation: 57728

No, there is no method to specify more than one file in a #include preprocessor directive.

Many people get around this dilemma by creating a monster include file that has multiple #include statements:
monster_include.h

#ifndef MONSTER_H
#define MONSTER_H
  #include <iostream>
  #include <string>
#endif

The disadvantage is that if any of these include files are changed, including ones not used by the source file, the source file will still be rebuilt.

I recommend creating an empty stencil header file and an empty stencil source file, then adding #include as required. The stencil can be copied then filled in as appropriate. This will save more typing time than use the megalithic include file.

Upvotes: 3

πάντα ῥεῖ
πάντα ῥεῖ

Reputation: 1

There's nothing available for c++ like in your java sample.

Roll your own header to include all stuff you need.

E.g.

AllProjectHeaders.h


#ifndef ALLPROJECT_HEADERS
#define ALLPROJECT_HEADERS

#include<cstdio>
#include<iostream>
// ...

#endif

Upvotes: 2

Related Questions