Team LiB   Previous Section   Next Section

8.1 Overview of the Standard Library

The standard library has 51 headers, each containing a set of macro, function, type, and object declarations. A header is sometimes called a header file, but that phrase is misleading. An implementation does not need to implement headers as external files, although it is often simplest to think of a header as a file that contains macro, type, and function declarations.

Almost all the names declared in the standard library are in the std namespace. Macros, of course, are not in any namespace, so it is important that you know which names are macros and which are not. The detailed descriptions in Chapter 13 tell you this information. The only other names that are outside the std namespace are the global operator new and operator delete functions, declared in the <new> header.

figs/acorn.gif

To use the standard library, you must #include the desired header or headers. Some implementations #include headers within other headers (e.g., <set> might #include <iterator>). The headers that a vendor includes within a header vary from one implementation to another, so code that compiles successfully with one vendor's environment might not compile in a different environment. The solution is to get in the habit of including all the headers you need.

If you see headers of the form <iostream.h>, the program was probably written in the days before the C++ standard. It might also mean that your compiler and library were written before C++ was standardized. Although some popular, old compilers are still in wide use, they have newer versions that provide much better support for the C++ standard. Following the C++ standard is the best way to achieve portability across recent compilers and libraries.

You must not add any declarations to the std namespace, although you can specialize templates that are declared in std. When you add your own specialization, you must obey all the constraints specified for the template, and the specialization must depend on at least one user-defined name that has external linkage. Otherwise, the behavior is undefined.

The following are brief descriptions of the contents of each header. The headers inherited from the C standard are marked as "C header." Some of these headers have improved C++ equivalents, which are also shown. For complete descriptions of these headers, see Chapter 13.

<algorithm>

Standard algorithms for copying, searching, sorting, and otherwise operating on iterators and containers. See Chapter 10 for more information about the standard algorithms.

<bitset>

Class template to hold a fixed-sized sequence of bits.

<cassert>

Runtime assertion-checking; C header.

<cctype>

Character classification and case conversion; C header (see also <locale>).

<cerrno>

Error codes; C header.

<cfloat>

Limits of floating-point types; C header (see also <limits>).

<ciso646>

Empty header because C declarations are incorporated in the C++ language; C header.

<climits>

Limits of integer types; C header (see also <limits>).

<clocale>

Locale-specific information; C header (see also <locale>).

<cmath>

Mathematical functions; C header.

<complex>

Complex numbers.

<csetjmp>

Nonlocal goto; C header.

<csignal>

Asynchronous signals; C header.

<cstdarg>

Macros to help implement functions that take a variable number of arguments; C header.

<cstddef>

Miscellaneous standard definitions; C header.

<cstdio>

Standard input and output; C header (see also <iostream> and related headers).

<cstdlib>

Miscellaneous functions and related declarations; C header.

<cstring>

String-handling functions; C header (see also <string>).

<ctime>

Date and time functions and types; C header.

<cwchar>

Wide character functions, including I/O; C header (see also <locale>, <iostream>, <string>, and other I/O-related headers).

<cwctype>

Wide character classification and case conversion; C header (see also <locale>).

<deque>

Deque (double-ended queue) standard container.

<exception>

Base exception class and functions related to exception-handling.

<fstream>

File-based stream I/O.

<functional>

Function objects; typically used with standard algorithms.

<iomanip>

I/O manipulators; used with standard I/O streams.

<ios>

Base class declarations for all I/O streams.

<iosfwd>

Forward declarations for I/O objects.

<iostream>

Declarations of standard I/O objects.

<istream>

Input streams and input/output streams.

<iterator>

Additional iterators for working with standard containers and algorithms. See Chapter 10 for more information.

<limits>

Limits of numerical types.

<list>

Standard linked list container.

<locale>

Locale-specific information for formatting and parsing numbers, dates, times, and currency values, plus character-related functions for classifying, converting, and comparing characters and strings.

<map>

Associative map (sometimes called a dictionary) standard container.

<memory>

Allocators, algorithms for uninitialized memory, and smart pointers (auto_ptr).

<new>

Global operator new and operator delete and other functions related to managing dynamic memory.

<numeric>

Numerical algorithms.

<ostream>

Output streams.

<queue>

Queue and priority queue container adapters.

<set>

Associative set container.

<sstream>

String-based I/O streams.

<stack>

Stack container adapter.

<stdexcept>

Standard exception classes.

<streambuf>

Low-level stream buffers; used by high-level I/O streams.

<string>

Strings and wide-character strings.

<strstream>

String streams that work with character arrays (see also <sstream>).

<typeinfo>

Runtime type information.

<utility>

Miscellaneous templates, such as pair, most often used with standard containers and algorithms.

<valarray>

Numerical arrays.

<vector>

Vector (array-like) standard container.

    Team LiB   Previous Section   Next Section