Home > Articles > Programming > C/C++

  • Print
  • + Share This
This chapter is from the book

The Standard C++ Library

In this section, we will briefly review the Standard C++ library. Figure D.3 lists the core C++ header files. The <exception>, <limits>, <new>, and <typeinfo> headers support the C++ language; for example, <limits> allows us to test properties of the compiler's integer and floating-point arithmetic support, and <typeinfo> offers basic introspection. The other headers provide generally useful classes, including a string class and a complex numeric type. The functionality offered by <bitset>, <locale>, <string>, and <typeinfo> loosely overlaps with the QBitArray, QLocale, QString, and QMetaObject classes in Qt.

Table D.3. Core C++ library header files

Header File



Template class for representing fixed-length bit sequences


Template class for representing complex numbers


Types and functions related to exception handling


Template class that specifies properties of numeric types


Classes and functions related to localization


Functions that manage dynamic memory allocation


Predefined types of exceptions for reporting errors


Template string container and character traits


Class that provides basic meta-information about a type


Template classes for representing value arrays

Standard C++ also includes a set of header files that deal with I/O, listed in Figure D.4. The standard I/O classes' design harks back to the 1980s and is needlessly complex, making them very hard to extend—so difficult, in fact, that entire books have been written on the subject. It also leaves the programmer with a Pandora's box of unresolved issues related to character encodings and platform-dependent binary representations of primitive data types.

Table D.4. C++ I/O library header files

Header File



Template classes that manipulate external files


I/O stream manipulators that take an argument


Template base class for I/O streams


Forward declarations for several I/O stream template classes


Standard I/O streams ( cin , cout , cerr , clog )


Template class that controls input from a stream buffer


Template class that controls output to a stream buffer


Template classes that associate stream buffers with strings


Template classes that buffer I/O operations


Classes for performing I/O stream operations on character arrays

Chapter 12 presents the corresponding Qt classes, which feature Unicode I/O as well as a large set of national character encodings and a platform-independent abstraction for storing binary data. Qt's I/O classes form the basis of Qt's inter-process communication, networking, and XML support. Qt's binary and text stream classes are very easy to extend to handle custom data types.

The early 1990s saw the introduction of the Standard Template Library (STL), a set of template-based container classes, iterators, and algorithms that slipped into the ISO C++ standard at the eleventh hour. Figure D.5 lists the header files that form the STL. The STL has a very clean, almost mathematical design that provides generic type-safe functionality. Qt provides its own container classes, whose design is partly inspired by the STL. We describe them in Chapter 11.

Table D.5. STL header files

Header File



General-purpose template functions


Double-ended queue template container


Templates that help construct and manipulate functors


Templates that help construct and manipulate iterators


Doubly linked list template container


Single-valued and multi-valued map template containers


Utilities for simplifying memory management


Template numeric operations


Queue template container


Single-valued and multi-valued set template containers


Stack template container


Basic template functions


Vector template container

Since C++ is essentially a superset of the C programming language, C++ programmers also have the entire C library at their disposal. The C header files are available either with their traditional names (e.g., <stdio.h>) or with new-style names with a c- prefix and no .h (e.g., <cstdio>). When we use the new-style version, the functions and data types are declared in the std namespace. (This doesn't apply to macros such as ASSERT(), because the preprocessor is unaware of namespaces.) The new-style syntax is recommended if your compiler supports it.

Figure D.6 lists the C library header files. Most of these offer functionality that overlaps with more recent C++ headers or with Qt. One notable exception is <cmath>, which declares mathematical functions such as sin(), sqrt(), and pow().

Table D.6. C++ header files for C library facilities

Header File



The ASSERT() macro


Functions for classifying and mapping characters


Macros related to error condition reporting


Macros that specify properties of primitive floating-point types


Alternative spellings for ISO 646 charset users


Macros that specify properties of primitive integer types


Functions and types related to localization


Mathematical functions and constants


Functions for performing non-local jumps


Functions for handling system signals


Macros for implementing variable argument list functions


Common definitions for several standard headers


Functions for performing I/O


General utility functions


Functions for manipulating char arrays


Types and functions for manipulating time


Extended multibyte and wide character utilities


Functions for classifying and mapping wide characters

This completes our quick overview of the Standard C++ library. On the Internet, Dinkumware offers complete reference documentation for the Standard C++ library at http://www.dinkumware.com/refxcpp.html, and SGI has a comprehensive STL programmer's guide at http://www.sgi.com/tech/stl/. The official definition of the Standard C++ library is in the C and C++ standards, available as PDF files or paper copies from the International Organization for Standardization (ISO).

In this appendix, we covered a lot of ground at a fast pace. When you start learning Qt from Chapter 1, you should find that the syntax is a lot simpler and clearer than this appendix might have suggested. Good Qt programming only requires the use of a subset of C++ and usually avoids the need for the more complex and obscure syntax that C++ makes possible. Once you start typing in code and building and running executables, the clarity and simplicity of the Qt approach will become apparent. And as soon as you start writing more ambitious programs, especially those that need fast and fancy graphics, the C++/Qt combination will continue to keep pace with your needs.

  • + Share This
  • 🔖 Save To Your Account