11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

92 Part II: Becoming a Functional C++ ProgrammerA definition for a typical math include file looks like this:// math include file:// provide prototypes for functions that might be useful// in more than one program// abs - return the absolute value of the argumentdouble abs(double d);// square - return the square of the argumentdouble square(double d);A program uses the math include file like this:// MyProgram -#include “math”using namespace std;// my code continues hereThe #include directive says, in effect, Replace this directive with the contentsof the math file.The #include directive doesn’t have the format of a C++ statement becauseit’s interpreted by a separate interpreter that executes before the C++ compilerstarts doing its thing. In particular, the # must be in column one and anend-of-line terminates the include statement. The actual file name must beenclosed in either quotes or brackets. Brackets are used for C++ library functions.Use the quotes for any includes that you create.The C++ environment provides include files such as cstdio and iostream. Infact, it’s iostream that contains the prototype for the setf() function usedin Chapter 4 to set output to hex mode.For years, programmers followed the custom of using the extension .h todesignate include files. In more recent years, the C++ ISO standard removedthe .h extension from standard include files. (For example, the include filecstdio was previously known as stdio.h.) Many programmers still stubbornlycling to the “.h gold standard” for their own programs. (What’s in aname? Evidence that even high-tech folks have traditions.)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!