In C++, what’s the difference between #include ” ” and #include<>?

What is the purpose of #include in C++?

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.

How do I decide to use angled brackets or quotes in the include statement?

The decision to use either #include ” ” or #include <> is based on whether the header file that is being “included” is predefined (by your implementation of C++) or if you wrote the header file yourself.

What’s the difference between using quotes and angled brackets in the include statement?

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 distinction tells 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.

#include<> is for predefined header files

If the header file is predefined 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>

#include ” ” is for header files the programmer defines

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"

Hiring? Job Hunting? Post a JOB or your RESUME on our JOB BOARD >>

Subscribe to our newsletter for more free interview questions.

One thought on “C++: #include ” ” vs. #include <>”