Question
Difference Between #include <...> and #include "..." in C and C++
Question
What is the difference between using angle brackets and double quotes in a C or C++ #include directive?
#include <filename>
#include "filename"
Specifically, how does the compiler or preprocessor decide where to look for the file in each case, and when should each form be used?
Short Answer
By the end of this page, you will understand how #include <...> and #include "..." work in C and C++, how the preprocessor searches for header files, when to use each form, and what common mistakes to avoid when organizing your code and dependencies.
Concept
In C and C++, #include tells the preprocessor to copy the contents of a header file into the current source file before compilation.
The two common forms are:
#include <header>
#include "header"
The main difference is where the preprocessor searches first.
#include <header>is typically used for system headers or library headers.#include "header"is typically used for your own project headers.
What usually happens
#include <header>
The preprocessor searches in the compiler's configured system include directories.
Examples:
#include <iostream>
#include <vector>
#include <stdio.h>
These files are normally provided by the standard library or installed libraries.
#include "header"
Mental Model
Think of #include like looking for a book.
#include <...>means: go to the library shelves first.#include "..."means: check my desk first, then go to the library if needed.
Your own notes are usually on your desk, so quotes make sense for project files. Standard reference books live in the library, so angle brackets make sense for system headers.
This mental model helps explain why the two forms often find different files even if the names are the same.
Syntax and Examples
Core syntax
#include <header>
#include "header"
Example 1: Standard library header
#include <iostream>
int main() {
std::cout << "Hello\n";
}
Why angle brackets?
iostream is a standard library header. The compiler already knows where standard library headers are installed, so angle brackets are the normal choice.
Example 2: Project header
Suppose your project has this file:
// math_utils.h
int add(int a, int b);
Then you include it like this:
#include "math_utils.h"
#include
{
a + b;
}
{
std::cout << (, ) << ;
}
Step by Step Execution
Consider this file structure:
project/
├── main.cpp
└── config.h
And main.cpp contains:
#include "config.h"
#include <iostream>
int main() {
std::cout << "Program started\n";
}
What happens step by step
1. The preprocessor reads #include "config.h"
Because quotes are used, it first looks in the local project area, usually the directory containing main.cpp.
It finds:
project/config.h
So it includes that file.
2. The preprocessor reads #include <iostream>
Because angle brackets are used, it looks in the compiler's system include paths.
It finds the standard library header for iostream.
3. The preprocessor builds the expanded source
It effectively replaces each line with the contents of the matching header.
Real World Use Cases
1. Including your own modules
In a project with files like database.h, auth.h, or config.h, developers usually write:
#include "database.h"
#include "auth.h"
#include "config.h"
This makes it clear these files belong to the project.
2. Using the C or C++ standard library
#include <string>
#include <vector>
#include <map>
These are standard headers provided by the compiler toolchain.
3. Including third-party libraries
Libraries installed through the system or package manager are often included with angle brackets:
#include <openssl/ssl.h>
#include <curl/curl.h>
Real Codebase Usage
In real projects, the difference is not just syntax style. It helps communicate ownership and location of headers.
Common conventions
Project headers use quotes
#include "logger.h"
#include "user_repository.h"
This signals: "these files are part of this codebase."
Standard and external headers use angle brackets
#include <vector>
#include <string>
#include <spdlog/spdlog.h>
This signals: "these files come from the toolchain or installed dependencies."
Common project patterns
1. Keep local includes separate from system includes
Many teams group includes like this:
#include <iostream>
#include <vector>
#include "config.h"
#
Common Mistakes
1. Using angle brackets for your own local header
Broken example:
#include <my_header.h>
This may fail if my_header.h is only in your project folder and not in the configured include paths.
Better:
#include "my_header.h"
2. Using quotes for standard library headers
This often still works if the compiler falls back to system paths, but it is not the normal convention.
Less clear:
#include "vector"
Better:
#include <vector>
3. Assuming all compilers behave exactly the same
Beginners sometimes assume the search rules are identical everywhere. In practice, compiler options and build tools can change include paths.
How to avoid this:
- follow standard conventions
- configure include directories correctly
- test builds across environments when possible
4. Naming a project header like a system header
Comparisons
| Form | Typical use | Search starts in | Common examples |
|---|---|---|---|
#include <...> | System or installed library headers | System/include paths | <iostream>, <vector>, <stdio.h> |
#include "..." | Project/local headers | Current file or local directory first, then include paths | "config.h", "user.h" |
#include <...> vs #include "..."
- Angle brackets emphasize external or system-provided headers.
- Quotes emphasize local or project-owned headers.
- In many compilers, quotes search locally first, then fall back to normal include paths.
Cheat Sheet
Quick rule
- Use
#include "file.h"for your own headers. - Use
#include <file>or#include <file.h>for standard library and installed library headers.
Syntax
#include "my_header.h"
#include <vector>
Search behavior
Quotes
#include "my_header.h"
Usually searches:
- local/current file directory first
- then configured include directories
Angle brackets
#include <vector>
Usually searches:
- system/include directories
Good examples
#include
FAQ
When should I use quotes in #include?
Use quotes for headers that belong to your own project, such as "config.h" or "user.h".
When should I use angle brackets in #include?
Use angle brackets for standard library headers and installed third-party library headers, such as <iostream> or <curl/curl.h>.
Do quotes and angle brackets always search completely different places?
Not always. In many compilers, quotes search the local directory first and then the normal include paths. Angle brackets usually skip the local-first step.
Can #include "file.h" still find system headers?
Often yes, if the compiler does not find a local file and then falls back to system include paths. But it is better to follow the normal convention.
Why did my local header not compile with angle brackets?
Because the compiler may only be searching system include paths for <...>, and your project directory may not be part of those paths.
Is this behavior identical in all compilers?
No. The exact rules can vary, especially with compiler options and build system settings. The common convention still applies across most environments.
What if my project header has the same name as a system header?
That can cause confusion or accidental mismatches. Use unique names or place project headers in named folders such as .
Mini Project
Description
Create a small C++ project with one local header and one standard library header to see how #include "..." and #include <...> are used together. This project demonstrates the common convention used in real programs: local project code uses quotes, while standard library code uses angle brackets.
Goal
Build and run a small program that includes a local header with quotes and a standard library header with angle brackets.
Requirements
- Create a local header file named
greeting.h. - Declare a function in
greeting.hthat returns a greeting message. - Include
greeting.hin your main source file using quotes. - Include
<iostream>in your main source file using angle brackets. - Print the greeting message to the console.
Keep learning
Related questions
Building More Fault-Tolerant Embedded C++ Applications for Radiation-Prone ARM Systems
Learn practical C++ and compile-time techniques to reduce soft-error damage in embedded ARM systems exposed to radiation.
Definition vs Declaration in C and C++: What’s the Difference?
Learn the difference between declarations and definitions in C and C++ with simple examples, common mistakes, and practical usage.
Difference Between ++i and i++ in C
Learn the difference between pre-increment and post-increment in C, how they behave, and which one to use in a for loop.