The
first chapter in this section introduces the Standard C++
string
class, which is a powerful tool that simplifies most of the text processing
chores you might have to do. The
string
class may be the most thorough string manipulation tool you’ve ever seen.
Chances are, anything you’ve done to character strings with lines of code
in C can be done with a member function call in the string class, including
append( ),
assign( ),
insert( ),
remove( ),
replace( ),
resize( ),
copy( ),
find( ),
rfind( ),
find_first_of( ),
find_last_of( ),
find_first_not_of( ),
find_last_not_of( ),
substr( ),
and
compare( ).
The operators
=,
+=,
and
[
]
are also overloaded to perform the intuitive operations. In addition,
there’s a “wide”
wstring
class designed to support international character sets. Both
string
and
wstring
(declared in
<string>,
not to be confused with C’s
<string.h>,
which is, in strict C++,
<cstring>)
are created from a common template class called
basic_string.
Note that the string classes are seamlessly integrated with iostreams,
virtually eliminating the need for you to ever use
strstream.
The
next chapter covers the
iostream
library.
Language
Support.
Elements inherent to the language itself, like implementation limits
in
<climits>
and
<cfloat>;
dynamic memory declarations in
<new>
like
bad_alloc
(the exception thrown when you’re out of memory) and
set_new_handler;
the
<typeinfo>
header for RTTI
and the
<exception>
header that declares the
terminate( )
and
unexpected( )
functions.
Diagnostics
Library.
Components C++ programs can use to detect and report errors. The
<exception>
header declares the standard exception classes and
<cassert>
declares the same thing as C’s
assert.h.
General
Utilities Library.
These components are used by other parts of the Standard C++ library, but you
can also use them in your own programs. Included are templatized versions of
operators
!=,
>,
<=,
and
>=
(to prevent redundant definitions), a
pair
template class
with a
tuple-making
template function,
a set of
function
objects
for support of the STL, and storage allocation functions for use with the STL
so you can easily modify the storage allocation mechanism.
Localization
Library.
This allows you to localize strings in your program to adapt to usage in
different countries,
including money, numbers, date, time, and so on.
Containers
Library.
This includes the Standard Template Library (described in the next section of
this appendix) and also the
bitsand
bit_stringclasses
in
<bits>
and
<bitstring>,
respectively. Both
bits
and
bit_string
are more complete implementations of the bitvector concept introduced in
Chapter 4 (see page
Error!
Bookmark not defined.
).
The
bits
template creates a fixed-sized array of bits that can be manipulated with all
the bitwise operators, as well as member functions like
set( ),
reset( ),
count( ),
length( ),
test( ),
any( ),
and
none( ).
There are also conversion operators
to_ushort( ),
to_ulong( ),
and
to_string( ).
The
bit_string
class is, by contrast, a dynamically sized array of bits, with similar
operations to
bits,
but also with additional operations that make it act somewhat like a
string.
There’s a fundamental difference in bit weighting: With
bits,
the right-most bit (bit zero) is the least significant bit, but with
bit_string,
the right-most bit is the
most
significant bit. There are no conversions between
bits
and
bit_string.
You’ll use
bits
for a space-efficient set of on-off flags and
bit_string
for manipulating arrays of binary values (like pixels).
Iterators
Library.
Includes iterators that are tools for the STL (described in the next section of
this appendix), streams, and stream buffers.
Numerics
Library.
The goal of this library is to allow the compiler implementor to take advantage
of the architecture of the underlying machine when used for numerical operations.
This way, creators of higher level numerical libraries can write to the
numerics library and produce efficient algorithms without having to customize
to every possible machine. The numerics library also includes the complex
number class
(which appeared in the first version of C++ as an example, and has become an
expected part of the library) in
float,
double,
and
long
double
forms.