Header File Syntax: <> vs ""

Why do some header files use angle brackets (<>) while others use quotes ("")?

The choice between angle brackets and quotes tells the compiler where to look for the header file. This is more than just a style choice - it affects how your program builds.

Angle Brackets (<>)

When you use angle brackets, like #include <iostream>, the compiler looks in the system include directories. These are folders where standard C++ headers and third-party libraries are installed. The exact locations depend on your compiler and operating system, but they're typically somewhere like:

  • /usr/include on Linux
  • C:\Program Files\Microsoft Visual Studio\...\include on Windows

Quotes ("")

When you use quotes, like #include "Character.h", the compiler first looks in the same directory as your source file. If it can't find the header there, it then checks related directories in your project. Only if it still can't find the file will it look in the system directories.

Here's how you typically use each:

// System headers use angle brackets
#include <iostream>
#include <string>
#include <vector>

// Your own headers use quotes
#include "Character.h"
#include "Weapon.h"

The general rule is:

  • Use angle brackets for headers that come with C++ or third-party libraries
  • Use quotes for headers you've created as part of your project

Following this convention makes your code more maintainable because other developers can quickly understand where each header comes from. It also helps the compiler work more efficiently since it knows where to look first.

Header Files

Explore how header files and linkers streamline C++ programming, learning to organize and link our code effectively

Questions & Answers

Answers are generated by AI models and may not have been reviewed. Be mindful when running any code on your device.

Including Headers in CPP Files
Why do we need to include the header file in its own cpp file? The cpp file already has all the class code!
Circular Dependencies
Can I have circular dependencies if I use pointers? I noticed the lesson showed a Character with a Sword pointer, and a Sword with a Character pointer. How does that work?
Header File Locations
How does the compiler know where to find my header files? What if they are in different folders?
Understanding #pragma once
Why do we need #pragma once? What does it do exactly?
Multiple Classes Per Header
Can I declare multiple classes in one header file? When should I do this?
Separating Declarations
Should I always move function definitions to cpp files? The lesson mentioned small functions can stay in the header - how do I decide?
Or Ask your Own Question
Get an immediate answer to your specific question using our AI assistant