incuded files

lets you have main, and then 2 header files, 1 and 2. header file 1 has already included header file 2. in main, you include header 1.

Is is ok to just include header 1 into main? does this "slow" it down? should you include both into main?

Rather than just answer yes or no, I shall explain how it works.

Here is what #include does:

When you compile your code, first the pre-processor runs. It looks through the file and everywhere it sees

#include <some file>

it takes that file and copies it completely into that place.

So, if header one includes header two, the pre-processor copies the entire header one into header two, and then the entire thing (header one and header two) gets copied into main.

So, at this point, there is no reason at all to include header two again in main. In fact, if you do that and it doesn't have header guards, it can break things.
thank you
what is the difference of including a .cpp file or a .h file.

if you were making a a new file, does it matter?
cpp files are (or should be) compiled and linked with other cpp files.

h files are not.

You should not #include cpp files.

See this:

http://cplusplus.com/forum/articles/10627/
Last edited on
Can header files also be included in double quotes?

I mean #include"iostream.h" instead of #include<iostream.h>
For starters, the standard header is <iostream>, not <iostream.h>.

"quotes" vs. <angle brackets> tells the compiler where to look for the header. If you use "quotes", the compiler will only look in the current directory (same directory as the source file).

If you use <angle brackets>, the compiler will look in standard include directories (these directories are listed in your compiler's settings somewhere). These directories hold the standard libs like <iostream> and platform API stuff like <Windows.h>.


So no, if you put #include "iostream" it will fail because you probably don't have a copy of the iostream header in the same directory as your source file.
Topic archived. No new replies allowed.