Appendix C

Standard Library Header Files

The interface to the C++ Standard Library consists of 78 header files, 26 of which present the C standard library. It’s often difficult to remember which header files you need to include in your source code, so this material provides a brief description of the contents of each header, organized into eight categories:

  • The C Standard Library
  • Containers
  • Algorithms, iterators, and allocators
  • General utilities
  • Mathematical utilities
  • Exceptions
  • I/O Streams
  • Threading library

THE C STANDARD LIBRARY

The C++ Standard Library includes the entire C Standard Library. The header files are generally the same, except for two points:

  • The header names are <cname> instead of <name.h>.
  • All the names declared in the header files are in the std namespace.
pen.gif

For backward compatibility, you can still include <name.h> if you want. However, that puts the names into the global namespace instead of the std namespace. We recommend avoiding this feature.

The following table provides a summary of the most useful functionality:

HEADER FILE NAME CONTENTS
<cassert> assert() macro.
image <ccomplex> Utilities to work with complex numbers.
<cctype> Character predicates and manipulation functions, such as isspace() and tolower().
<cerrno> Defines errno expression.
image <cfenv> Supports the floating-point environment, such as floating-point exceptions, rounding, and so on.
<cfloat> C-style defines related to floating-point arithmetic, such as FLT_MAX.
image <cinttypes> Defines a number of macros to use with the printf(), scanf() and similar functions. Also includes a few functions to work with intmax_t.
<ciso646> In C, the <iso646.h> file defines macros and, or, etc. In C++, those are keywords, so they are not in this header.
<climits> C-style limit defines, such as INT_MAX.
<clocale> A few localization macros and functions like LC_ALL and setlocale().
<cmath> Math utilities, including trigonometric functions, sqrt(), fabs(), and others.
<csetjmp> setjmp() and longjmp(). Never use these in C++!
<csignal> signal() and raise(). Avoid these in C++.
image <cstdalign> Alignment related macro __alignas_is_defined.
<cstdarg> Macros and types for processing variable-length argument lists.
image <cstdbool> Boolean type related macro __bool_true_false_are_defined.
<cstddef> Important constants such as NULL, and important types such as size_t.
image <cstdint> Defines a number of standard integer types such as int8_t, int64_t and so on. It also includes macros specifying minimum and maximum values of those types.
<cstdio> File operations, including fopen() and fclose(). Formatted I/O: printf(), scanf(), and family. Character I/O: getc(), putc(), and family. File positioning: fseek(), ftell().
<cstdlib> Random numbers with rand() and srand(). The abort() and exit() functions, which you should avoid. C-style memory allocation functions: calloc(), malloc(), realloc(), free(). C-style searching and sorting with qsort() and bsearch(). String to number conversions: atof(), atoi(), etc.
<cstring> Low-level memory management functions, including memcpy() and memset(). C-style string functions, such as strcpy() and strcmp(). Secure versions such as strcpy_s(). Defines NULL and size_t as well.
image <ctgmath> Just includes <ccomplex> and <cmath>.
<ctime> Time-related functions, including time() and localtime().
image <cuchar> Defines a number of Unicode-related macros, and functions like mbrtoc16().
<cwchar> Versions of string, memory, and I/O functions for wide characters.
<cwctype> Versions of functions in <cctype> for wide characters: iswspace(), towlower(), and so on.

CONTAINERS

The definitions for the STL containers can be found in 12 header files:

HEADER FILE NAME CONTENTS
image <array> The array class template.
<bitset> The bitset class template.
<deque> The deque class template.
image <forward_list> The forward_list class template.
<list> The list class template.
<map> The map and multimap class templates.
<queue> The queue and priority_queue class templates.
<set> The set and multiset class templates.
<stack> The stack class template.
image <unordered_map> The unordered_map and unordered_multimap class templates.
image <unordered_set> The unordered_set and unordered_multiset class templates.
<vector> The vector class template and the vector<bool> specialization.

Each of these header files contains all the definitions you need to use the specified container, including iterators. Chapter 12 describes these containers in detail.

ALGORITHMS, ITERATORS, AND ALLOCATORS

The “rest” of the STL can be found in five different header files:

HEADER FILE NAME CONTENTS
<algorithm> Prototypes for most of the algorithms in the STL.
<functional> Defines the built-in function objects, negators, binders, and adaptors.
<iterator> Definitions of iterator_traits, iterator tags, iterator, reverse_iterator, insert iterators (such as back_inserter), and stream iterators.
<memory> Defines the default allocator, some utility functions for dealing with uninitialized memory inside containers, and the important C++11 shared_ptr and unique_ptr smart pointer class templates.
<numeric> Prototypes for some numerical algorithms: accumulate(), inner_product(), partial_sum(), adjacent_difference(), and a few others.

GENERAL UTILITIES

The Standard Library contains some general-purpose utilities in several different header files:

HEADER FILE NAME CONTENTS
image <chrono> Defines the Chrono library. See Chapter 16.
image <codecvt> Provides code conversion facets for various character encodings.
image <initializer_list> Defines the initializer_list class. See Chapter 9.
<limits> Defines the numeric_limits class template, and specializations for most built-in types. See Chapter 11.
<locale> Defines the locale class, the use_facet() and has_facet() template functions, and the various facet families. See Chapter 14.
<new> Defines the bad_alloc exception and set_new_handler() function. Prototypes for all six forms of operator new and operator delete. See Chapter 18.
image <random> Defines the random number generation library. See Chapter 16.
image <ratio> Defines the Ratio library to work with compile-time rational numbers. See Chapter 16.
image <regex> Defines the regular expression library. See Chapter 14.
<string> Defines the basic_string class template and the typedef instantiations of string and wstring.
image <system_error> Defines error categories and error codes.
image <tuple> Defines the tuple class template as a generalization of the pair class template. See Chapter 16.
image <type_traits> Defines type traits for use in template metaprogramming. See Chapter 20.
image <typeindex> Defines a simple wrapper for type_info, which can be used as an index type in associative containers and in unordered associative containers.
<typeinfo> Defines the bad_cast and bad_typeid exceptions. Defines the type_info class, objects of which are returned by the typeid operator. See Chapter 8 for details on typeid.
<utility> Defines the pair class template. See Chapter 12.

MATHEMATICAL UTILITIES

C++ provides some facilities for numeric processing. These capabilities are not described in detail in this book; for details, consult one of the Standard Library references listed in the Annotated Bibliography.

HEADER FILE NAME CONTENTS
<complex> Defines the complex class template for processing complex numbers.
<valarray> Defines valarray and related classes and class templates for processing mathematical vectors and matrices.

EXCEPTIONS

Exceptions and exception support are covered in Chapter 10. Two header files provide most of the requisite definitions, but some exceptions for other domains are defined in the header file for that domain.

HEADER FILE NAME CONTENTS
<exception> Defines the exception and bad_exception classes, and the set_unexpected(), set_terminate(), and uncaught_exception() functions.
<stdexcept> Non-domain-specific exceptions not defined in <exception>.

I/O STREAMS

The following table lists all the header files related to I/O streams in C++. However, normally your applications only need to include <fstream>, <iomanip>, <iostream>, <istream>, <ostream>, and <sstream>. Consult Chapter 15 for details.

HEADER FILE NAME CONTENTS
<fstream> Defines the basic_filebuf, basic_ifstream, basic_ofstream, and basic_fstream classes. Declares the filebuf, wfilebuf, ifstream, wifstream, ofstream, wofstream, fstream, and wfstream typedefs.
<iomanip> Declares the I/O manipulators not declared elsewhere (mostly in <ios>).
<ios> Defines the ios_base and basic_ios classes. Declares most of the stream manipulators. You rarely have to include this header directly.
<iosfwd> Forward declarations of the templates and typedefs found in the other I/O stream header files. You rarely need to include this header directly.
<iostream> Declares cin, cout, cerr, clog, and the wide-character counterparts. Note that it’s not just a combination of <istream> and <ostream>.
<istream> Defines the basic_istream and basic_iostream classes. Declares the istream, wistream, iostream, and wiostream typedefs.
<ostream> Defines the basic_ostream class. Declares the ostream and wostream typedefs.
<sstream> Defines the basic_stringbuf, basic_istringstream, basic_ostringstream, and basic_stringstream classes. Declares the stringbuf, wstringbuf, istringstream, wistringstream, ostringstream, wostringstream, stringstream, and wstringstream typedefs.
<streambuf> Defines the basic_streambuf class. Declares the typedefs streambuf and wstreambuf. You rarely have to include this header directly.
<strstream> Deprecated.

image THREADING LIBRARY

C++11 includes a threading library, which allows you to write platform-independent multithreaded applications. See Chapter 22 for details. The threading library consists of the following header files:

HEADER FILE NAME CONTENTS
<atomic> Defines the atomic types, atomic<T>, and atomic operations.
<condition_variable> Defines the condition_variable and condition_variable_any classes.
<future> Defines future, promise, packaged_task and async().
<mutex> Defines the different mutex and lock classes, and call_once().
<thread> Defines the thread class.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset