Using pragmas

Associated with symbols and conditional compilation is the compiler directive, #pragma once. Pragmas are directives specific to the compiler, and different compilers will support different pragmas. Visual C++ defines the #pragma once to solve the problem that occurs when you have multiple header files each including similar header files. The problem is that it may result in the same items being defined more than once and the compiler will flag this as an error. There are two ways to do this, and the <iostream> header file that you include next uses both of these techniques. You can find this file in the Visual C++ include folder. At the top of the file you will find the following:

    // ostream standard header     #pragma once 

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.