Using C++ Library Headers

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 C++ library header includes any other C++ library headers it needs to define needed types. (Always include explicitly any C++ library 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.

All names other than operator delete and operator new in the C++ library headers are defined in the std namespace, or in a namespace nested within the std namespace. Including a C++ library header does not introduce any library names into the current 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 write this declaration immediately after all include directives, you can otherwise ignore namespace considerations in the remainder of the translation unit. Note that macro names are not subject to the rules for nesting namespaces.

Note that the C Standard headers behave mostly as if they include no namespace declarations. If you include, for example, <cstdlib>, you should call std::abort() to cause abnormal termination, but if you include <stdlib.h>, you should call abort(). (The C++ Standard is intentionally vague on this topic, so you should stick with just the usages described here for maximum portability.)

Unless specifically indicated otherwise, you may not define names in the std namespace, or in a namespace nested within the std namespace.

Copyright note

Certain materials included or referred to in this document are copyright P.J. Plauger and/or Dinkumware, Ltd. or are based on materials that are copyright P.J. Plauger and/or Dinkumware, Ltd.

Notwithstanding the meta-data for this document, copyright information for this document is as follows:

Copyright © IBM Corp. 1999, 2014. & Copyright © P.J. Plauger and/or Dinkumware, Ltd. 1992-2006.