Header Files

Header File Syntax: <> vs ""

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

3D art showing a character in a bar

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.

Answers to questions are automatically generated and may not have been reviewed.

3D art showing a progammer setting up a development environment
Part of the course:

Intro to C++ Programming

Become a software engineer with C++. Starting from the basics, we guide you step by step along the way

Free, unlimited access

This course includes:

  • 60 Lessons
  • Over 200 Quiz Questions
  • 95% Positive Reviews
  • Regularly Updated
  • Help and FAQ
Free, Unlimited Access

Professional C++

Comprehensive course covering advanced concepts, and how to use them on large-scale projects.

Screenshot from Warhammer: Total War
Screenshot from Tomb Raider
Screenshot from Jedi: Fallen Order
Contact|Privacy Policy|Terms of Use
Copyright © 2024 - All Rights Reserved