HPlogo HP C++ Programmer's Guide: HP 9000 Series Workstations and Servers > Chapter 2 The HP C++ Preprocessor

Source File Inclusion

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

You can include the contents of other files within the source file prior to compilation by using the #include directive.

Syntax

include-directive ::=
     #include <filename>
     #include "filename"
     #include identifier

Description

The #include preprocessing directive causes HP C++ to read source input from the file named in the #include directive. Usually, include files are named:

filename.h

If the file name is enclosed in angle brackets (< >), the system directory is searched to find the named file. If the file name is enclosed in double quotation marks ("), HP C++ searches your current directory for the specified file. Refer to "System Library and Header Files" in Chapter 3 “Compiling and Executing HP C++ Programs” for a detailed description of how an #include file is found.

Files that are included may contain #include directives themselves. HP C++ supports a nesting level of at least 35 #include files.

The arguments to the #include directive are subject to macro replacement before the directive processes them. Thus, if you use an #include directive of the form #include identifier, identifier must be a previously defined macro that when expanded produces one of the above defined forms of the #include directive. Refer to the next section, "Macro Replacement," for more information on macros.

Error messages produced by HP C++ indicate the name of the #include file where the error occurred, as well as the line number within the file.

Examples

#include <iostream.h>
#include "myheader.h"
#ifdef   MINE
#   define  filename  "file1.h"
#else
#   define  filename  "file2.h"
#endif
#include filename
© Hewlett-Packard Development Company, L.P.