Headers

Header Files

The C++ standard specifies the entire set of header files that
must be available to all hosted implementations. Actually, the
word "files" is a misnomer, since the contents of the
headers don't necessarily have to be in any kind of external
file. The only rule is that when one #include's a
header, the contents of that header become available, no matter
how.

That said, in practice files are used.

There are two main types of include files: header files related
to a specific version of the ISO C++ standard (called Standard
Headers), and all others (TR1, C++ ABI, and Extensions).

Two dialects of standard headers are supported, corresponding to
the 1998 standard as updated for 2003, and the current 2011 standard.

C++98/03 include files. These are available in the default compilation mode, i.e. -std=c++98 or -std=gnu++98.

Table 3.2. C++ 1998 Library Headers

algorithm

bitset

complex

deque

exception

fstream

functional

iomanip

ios

iosfwd

iostream

istream

iterator

limits

list

locale

map

memory

new

numeric

ostream

queue

set

sstream

stack

stdexcept

streambuf

string

utility

typeinfo

valarray

vector

Table 3.3. C++ 1998 Library Headers for C Library Facilities

cassert

cerrno

cctype

cfloat

ciso646

climits

clocale

cmath

csetjmp

csignal

cstdarg

cstddef

cstdio

cstdlib

cstring

ctime

cwchar

cwctype

C++11 include files. These are only available in C++11 compilation
mode, i.e. -std=c++11 or -std=gnu++11.

Mixing Headers

First, mixing different dialects of the standard headers is not
possible. It's an all-or-nothing affair. Thus, code like

#include <array>
#include <functional>

Implies C++11 mode. To use the entities in <array>, the C++11
compilation mode must be used, which implies the C++11 functionality
(and deprecations) in <functional> will be present.

Second, the other headers can be included with either dialect of
the standard headers, although features and types specific to C++11
are still only enabled when in C++11 compilation mode. So, to use
rvalue references with __gnu_cxx::vstring, or to use the
debug-mode versions of std::unordered_map, one must use
the std=gnu++11 compiler flag. (Or std=c++11, of course.)

A special case of the second rule is the mixing of TR1 and C++11
facilities. It is possible (although not especially prudent) to
include both the TR1 version and the C++11 version of header in the
same translation unit:

#include <tr1/type_traits>
#include <type_traits>

Several parts of C++11 diverge quite substantially from TR1 predecessors.

The C Headers and namespace std

The standard specifies that if one includes the C-style header
(<math.h> in this case), the symbols will be available
in the global namespace and perhaps in
namespace std:: (but this is no longer a firm
requirement.) On the other hand, including the C++-style
header (<cmath>) guarantees that the entities will be
found in namespace std and perhaps in the global namespace.

Usage of C++-style headers is recommended, as then
C-linkage names can be disambiguated by explicit qualification, such
as by std::abort. In addition, the C++-style headers can
use function overloading to provide a simpler interface to certain
families of C-functions. For instance in <cmath>, the
function std::sin has overloads for all the builtin
floating-point types. This means that std::sin can be
used uniformly, instead of a combination
of std::sinf, std::sin,
and std::sinl.

Precompiled Headers

There are three base header files that are provided. They can be
used to precompile the standard headers and extensions into binary
files that may the be used to speed compiles that use these headers.