Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

#include can be used two ways?

Status
Not open for further replies.

Stopher

Programmer
Jan 12, 2002
29
US
I've seen two different uses of the #include directive...

#include "iostream.h"

and

#include <iostream>


both seem to work, but some people claim they are different somehow...can someone explain how?

Thanx,
Da Stopher
 
One searches the immediate directory and the other also searches sub-directories. At least this is what I understand!
tellis.gif

programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.
 
The <> form skips the current directory and goes right to the place standard hearders are located. The &quot;&quot; form first checks the current directory, then the standard headers. The &quot;&quot; form is normally used for headers you write (and keep in your project directory). You can also make replacements for standard headers this way. If you write a file called iostream.h and put it in your project directory, #include &quot;iostream.h&quot; will include your file if it can find it, and the system one if it can't; #include <iostream.h> will include the file located in the standard include path in every case.

By the way, never use iostream.h; it's not a part of standard C++ and provided only for backwards compatibility. Use iostream (without the &quot;.h&quot;) instead.
 
chipper: if <> skips the current directory then why do some compilers have an option to treat &quot; &quot; as < >???

[bugeyed]
tellis.gif

programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.
 
qednick - it depends on the compiler. Some have default include paths and will pick up the stuff in the compiler's include directory. It depends on what the default include paths are. This is sometimes set in the environment variables.
 
Ahhh, I should have guessed - thanks xwb
tellis.gif

programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.
 
May I add some words? <> form is not &quot;skipped current directory&quot; only. C++ Standard defines that <header> points to the embedded, standard header implementation. It may be not an ordinal text file in any directory but compiler-embedded database reference or what else...
So, <> form must be used for language-defined headers only, and quoted form for user-defined headers.
It's right, .h suffix excluded now for standard headers. For example, <iostream.h> points to &quot;old stream library&quot; in some C++ compilers. Sometimes they implements both &quot;old&quot; and true standard &quot;new&quot; <iostream> headers (libraries). They are incompatible.
 
Yup, that's true; the standard headers need not be actual files, so there may not be an actual path to them. The underlying principle remains the same, however; <> goes right to the standard include &quot;files&quot; (whether or not they're actual files), while &quot;&quot; checks files in (actually, relative to) the the current directory before checking the standard ones (which, again, may not be true files).

To get really technical, there's nothing that says the &quot;&quot; form has to search the current directory (since theoretically, there may not even be such a thing as a directory on every platform), but in practice, that's where it usually looks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top