The purpose of using the #include directive is so that a copy of the file that is named in the include directive can be placed in the same location as the file in which the directive is used.
The decision to use either #include ” ” or #include <> is based on whether the header file that is being “included” ispredefined (by yourimplementation of C++) or if you wrote the header file yourself.
The reason that quotes are used sometimes and angled brackets are used other times is that the compiler will look in different places for the header file depending on whether quotes or brackets are used. So, the distinctiontells the compiler where to look for the header file. For header files in angular brackets, the compiler will look wherever predefined header files are kept in your implementation of C++. Remember that not all implementations of C++ are the same, so this location may be different across different implementations. If the header file is inside quotes, then the compiler will look inside the current directory for that header file, or it will look wherever header files defined by programmers are stored on your system.
If the header file ispredefined then you would simply write the header file name in angular brackets, and it would look like this (assuming we have a predefined header file name iostream):
#include <iostream>
If you (the programmer) wrote your own header file then you would write the header file name in quotes. So, suppose you wrote a header file called myfile.h, then this is an example of how you would use the include directive to include that file:
#include "myfile.h"
Would you like to thankProgrammerInterview.com for being a helpful free resource?Then why not tell a friend about us, orsimply add a link to this page from your webpage using the HTML below.
Link to this page:
Please bookmark with social media, your votes are noticed and appreciated: