You include the contents of a standard header by naming it in an include directive, as in:
#include <iostream> /* include I/O facilities */
You can include the standard headers in any order, a standard header more than once, or two or more standard headers that define the same macro or the same type. Do not include a standard header within a declaration. Do not define macros that have the same names as keywords before you include a standard header.
A Standard C++ header includes any other Standard C++ headers it needs to define needed types. (Always include explicitly any Standard C++ headers needed in a translation unit, however, lest you guess wrong about its actual dependencies.) A Standard C header never includes another standard header. A standard header declares or defines only the entities described for it in this document.
Every function in the library is declared in a standard header. Unlike in Standard C, the standard header never provides a masking macro, with the same name as the function, that masks the function declaration and achieves the same effect.
If an implementation supports namespaces, all names in the Standard C++ headers are defined in the std
namespace.
You refer to the name cin
, for example, as std::cin
. Alternatively, you can write the declaration:
using namespace std;
which promotes all library names into the current namespace. If you include one of the C standard headers, such as
<stdio.h>
, the individual names declared or defined in that header are promoted for you. Note that macro names are
not subject to the rules for nesting namespaces.