Sunday, July 12, 2009

What's the difference in #include <iostream> and #include "foo.h" with c++ ?

When you use an include file in angle brackets like %26lt;iostream%26gt; the compiler automatically looks in system defined places like /usr/include and files specified within your $PATH variable. When an include file is in quotes like "foo.h" the compiler looks in user defined directories that are passed to the compiler via the -I option so, for instance, if you compile with something like -I /code/mystuff the compiler will look for your header files in that directory.





Also iostream is a standard system header file. Something like foo.h is clearly a user defined file.

What's the difference in #include %26lt;iostream%26gt; and #include "foo.h" with c++ ?
files within " " are searched for in the current directory...


whereas files enclosed within %26lt; %26gt; are searched in all paths in the $PATH environment....





basically if u want to include your own custom header files then use " " and place the header files in the same directory...





if u want to use the system or library header files use %26lt; %26gt;, it will be searched from its path....
Reply:iostream stands for input output stream


it is standard header usedin c++


but


#include%26lt;foo.h%26gt;


this header is created by any user


becoz a user can create his own header in c++
Reply:Things like iostream and math are libraries that are included within most C++ compilers and are commonly used. You could also use them on a path include, also, but it is easier to just use the name.





Things in quotes are anything that is outside of the path, so you could actually do something like include "../../../blah.h" which will give you 3 levels above the PATH.

cvs

No comments:

Post a Comment