C
Standard Library Header Files

The interface to the C++ Standard Library consists of 87 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 appendix 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 support library

THE C STANDARD LIBRARY

The C++ Standard Library includes almost 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 <cname> header files are in the std namespace.

The following table provides a summary of the most useful functionality. Note that it’s recommended to avoid using C functionality, and instead use equivalent C++ features whenever possible.

HEADER FILENAME CONTENTS
<cassert> assert() macro
<ccomplex> Only includes <complex>. This header is deprecated since C++17.
<cctype> Character predicates and manipulation functions, such as isspace() and tolower()
<cerrno> Defines errno expression, a macro to get the last error number for certain C functions.
<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
<cinttypes> Defines a number of macros to use with the printf(), scanf(), and similar functions. This header also includes a few functions to work with intmax_t.
<ciso646> In C, the <iso646.h> file defines macros and, or, and so on. In C++, those are keywords, so this header is empty.
<climits> C-style limit defines, such as INT_MAX. It is recommended to use the C++ equivalents from <limits> instead.
<clocale> A few localization macros and functions like LC_ALL and setlocale(). See also the C++ equivalents in <locale>.
<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++.
<cstdalign> Alignment-related macro __alignas_is_defined. This is deprecated since C++17.
<cstdarg> Macros and types for processing variable-length argument lists
<cstdbool> Boolean type-related macro __bool_true_false_are_defined. This is deprecated since C++17.
<cstddef> Important constants such as NULL, and important types such as size_t
<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() and ftell(). It is recommended to use C++ streams instead. (See the section “I/O Streams,” later in this appendix.)
<cstdlib> Random numbers with rand() and srand() (deprecated since C++14; use the C++ <random> instead). This header includes the abort() and exit() functions, which you should avoid; C-style memory allocation functions calloc(), malloc(), realloc(), and free(); C-style searching and sorting with qsort() and bsearch(); string to number conversions: atof(), atoi(); a set of functions related to multibyte/wide string manipulation.
<cstring> Low-level memory management functions, including memcpy() and memset(). This header includes C-style string functions, such as strcpy() and strcmp().
<ctgmath> Only includes <complex> and <cmath>. This header is deprecated since C++17.
<ctime> Time-related functions, including time() and localtime()
<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 Standard Library containers can be found in 12 header files.

HEADER FILENAME CONTENTS
<array> The array class template
<bitset> The bitset class template
<deque> The deque class template
<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
<unordered_map> The unordered_map and unordered_multimap class templates
<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 17 describes these containers in detail.

ALGORITHMS, ITERATORS, AND ALLOCATORS

The following header files define the available Standard Library algorithms, iterators, and allocators.

HEADER FILENAME CONTENTS
<algorithm> Prototypes for most of the algorithms in the Standard Library. See Chapter 18.
image <execution> Defines the execution policy types for use with the Standard Library algorithms. See Chapter 18.
<functional> Defines the built-in function objects, negators, binders, and adaptors. See Chapter 18.
<iterator> Definitions of iterator_traits, iterator tags, iterator, reverse_iterator, insert iterators (such as back_insert_iterator), and stream iterators. See Chapter 21.
<memory> Defines the default allocator, functions for dealing with uninitialized memory inside containers, unique_ptr, shared_ptr, make_unique(), and make_shared(), introduced in Chapter 1.
image <memory_resource> Defines polymorphic allocators and memory resources. See Chapter 21.
<numeric> Prototypes for some numerical algorithms: accumulate(), inner_product(), partial_sum(), adjacent_difference(), and a few others. See Chapter 18.
<scoped_allocator> An allocator that can be used with nested containers such as a vector of strings, or a vector of maps.

GENERAL UTILITIES

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

HEADER FILENAME CONTENTS
image <any> Defines the any class. See Chapter 20.
image <charconv> Defines the chars_format enumeration class, the from_chars() and to_chars() functions, and related structs.
<chrono> Defines the chrono library. See Chapter 20.
<codecvt> Provides code conversion facets for various character encodings. This header is deprecated since C++17.
image<filesystem> Defines all available classes and functions to work with the filesystem. See Chapter 20.
<initializer_list> Defines the initializer_list class. See Chapter 1.
<limits> Defines the numeric_limits class template, and specializations for most built-in types. See Chapter 16.
<locale> Defines the locale class, the use_facet() and has_facet() function templates, and the various facet families. See Chapter 19.
<new> Defines the bad_alloc exception and set_new_handler() function. This header also defines the prototypes for all six forms of operator new and operator delete. See Chapter 15.
image<optional> Defines the optional class. See Chapter 20.
<random> Defines the random number generation library. See Chapter 20.
<ratio> Defines the Ratio library to work with compile-time rational numbers. See Chapter 20.
<regex> Defines the regular expressions library. See Chapter 19.
<string> Defines the basic_string class template and the type aliases string and wstring. See Chapter 2.
image<string_view> Defines the basic_string_view class template and the type aliases string_view and wstring_view. See Chapter 2.
<system_error> Defines error categories and error codes.
<tuple> Defines the tuple class template as a generalization of the pair class template. See Chapter 20.
<type_traits> Defines type traits for use with template metaprogramming. See Chapter 22.
<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 10 for details on typeid.
<utility> Defines the pair class template and make_pair() (see Chapter 17). This header also defines utility functions such as swap(), exchange(), move(), and more.
image<variant> Defines the variant class. See Chapter 20.

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 in Appendix B.

HEADER FILENAME CONTENTS
<complex> Defines the complex class template for working with complex numbers.
<valarray> Defines valarray and related classes and class templates for working with mathematical vectors and matrices.

EXCEPTIONS

Exceptions and exception support are covered in Chapter 14. 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 FILENAME 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 13 for details.

HEADER FILENAME CONTENTS
<fstream> Defines the basic_filebuf, basic_ifstream, basic_ofstream, and basic_fstream classes. This header declares the filebuf, wfilebuf, ifstream, wifstream, ofstream, wofstream, fstream, and wfstream type aliases.
<iomanip> Declares the I/O manipulators not declared elsewhere (mostly in <ios>).
<ios> Defines the ios_base and basic_ios classes. This header declares most of the stream manipulators. You rarely have to include this header directly.
<iosfwd> Forward declarations of the templates and type aliases 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. This header declares the istream, wistream, iostream, and wiostream type aliases.
<ostream> Defines the basic_ostream class. This header declares the ostream and wostream type aliases.
<sstream> Defines the basic_stringbuf, basic_istringstream, basic_ostringstream, and basic_stringstream classes. This header declares the stringbuf, wstringbuf, istringstream, wistringstream, ostringstream, wostringstream, stringstream, and wstringstream type aliases.
<streambuf> Defines the basic_streambuf class. This header declares the type aliases streambuf and wstreambuf. You rarely have to include this header directly.
<strstream> Deprecated.

THREADING SUPPORT LIBRARY

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

HEADER FILENAME 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 call_once() and the different non-shared mutex and lock classes.
<shared_mutex> Defines the shared_mutex, shared_timed_mutex, and shared_lock classes.
<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