Basic question regarding <iostream>

Hello,

I've been programming in C++ for a few weeks. And up until now, I've just been using the "std_lib_facilities.h" header by Bjarne Stoustroup. Now I want to start with an emty project, so I created one in Xcode - and found that

#include <iostream>

was written at the top of my main.cpp file. I found an FAQ from this site which explained that it was a header file that facilitates input and output. However, why is the "file" written that way, i.e. with brackets? Usually when I include header files I just write #include "filename.h", so I was wondering why it was written with <...> in this case.



Last edited on
closed account (z05DSL3A)
#include <> tell the pre-processor to search for the file in an implementation dependent manner.

#include "" tell the pre-processor to search for the file in the project directory first and then the implementation dependent manner.
There are two ways to include a file: with angle brackets or with double-quotes. The difference between them is technically "implementation defined". However, the basic idea is that when you use angle brackets the file will be searched for in the standard include directories (as defined by the implementation). But when you use double-quotes the file will be searched for in the current directory first, and then the standard directories. Therefore, when including the standard include files you should use angle brackets.

If you say include "iostream" it will probably still read the standard include file. But if you make a file of your own called iostream and put it in your current directory, then saying include "iostream" will include your own file whereas saying include <iostream> will still include the standard file.
Topic archived. No new replies allowed.