Hex Editor - Binary File Editing Software for Windows
Docs

# #include directive

`#include` directive physically includes the contents of a specified file into the current file.

Syntax:

``````#include "filename"
``````

or

``````#include <filename>
``````

When used in its first form, the referenced file is searched in the same folder as the current file.

For example, let us have following two files:

`file1.h`

``````struct A
{
// …
};
``````

And `file2.h`:

``````#include "file1.h"

struct B
{
A a;
};
``````

If there was no `#include` directive in `file2.h`, you would not be able to add this file to a Structure Library, as it uses an undefined type `A`. But preprocessor, which runs on the file before it is compiled, transforms the file into the following:

``````struct A
{
// …
};

struct B
{
A a;
};
``````

That is, it physically inserts the contents of `file1.h` into `file2.h`, thus, making `file2.h` compilable. See also the `#pragma once` directive.

## Using Absolute and Relative Paths

Both syntax forms, form 1 and form 2 allow you to specify absolute or relative paths, for example:

``````// will use an absolute path
#include "c:\Projects\definitions.h"

// includes "definitions.h" file, located in "inc" sibling
#include "..\inc\definitions.h"

// includes "definitions.h" file, located in "lib" subdirectory
// of one of standard include paths.
#include <lib\definitions.h>
``````