Include directive

An include directive instructs a text file processor to replace the directive text with the content of a specified file.

The act of including may be logical in nature. The processor may simply process the include file content at the location of the directive without creating a combined file.

Different processors may use different syntax. The C preprocessor (used with C, C++ and in other contexts) defines an include directive as a line that starts #include and is followed by a file specification. COBOL defines an include directive indicated by copy in order to include a copybook.

Generally, for C/C++ the include directive is used to include a header file, but can include any file. Although relatively uncommon, it is sometimes used to include a body file such as a .c file.

The include directive can support encapsulation and reuse. Different parts of a system can be segregated into logical groupings yet rely on one another via file inclusion. C and C++ are designed to leverage include while also optimizing build time by allowing declaration separate from implementation. The included information can be minimized to only declarations.

As many consider that including file content has significant drawbacks, newer languages have been designed without an include directive. Languages such as Java and C# support modularization via an import concept that allows a module to use the assets of another module at a conceptual level; not by including text.