Programming and Graphics

(Kiana) #1

2.5 System header files 39


For example, putting at the beginning of the code the statement:

#include <iostream>

instructs the C++ preprocessor to attach a header file containing the definition,
but not the implementation, of functions in the input/output stream library.
In the Fedora Core 5 Linux distribution, theiostreamheader file is located in
the/usr/include/c++/4.1.1directory.


Thus, the main function of a code that uses this library has the general
structure:


#include <iostream>
...
int main()
{
...
return 0;
}

where the three dots denote additional lines of code.


Similarly, putting at the beginning of a source code the statement:

#include<cmath>

ensures the availability of the C++ mathematical library. In this case,cmath
is a header file containing the definition, but not the implementation, of math-
ematical functions.


Thus, the main function of a code that uses both the input/output and
the mathematical libraries has the general syntax:


#include <iostream>
#include <cmath>
...
int main()
{
...
return 0;
}

where the three dots denote additional lines of code.


A statement following the # character in a C++ code is acompileror
preprocessor directive.Other directives are available.

Free download pdf