3.2.3 Dealing with the Characters in a string
Often we need to deal with the individual characters in a string. We might want to check to see whether a string contains any whitespace, or to change the characters to lowercase, or to see whether a given character is present, and so on.
One part of this kind of processing involves how we gain access to the characters themselves. Sometimes we need to process every character. Other times we need to process only a specific character, or we can stop processing once some condition is met. It turns out that the best way to deal with these cases involves different language and library facilities.
The other part of processing characters is knowing and/or changing the characteristics of a character. This part of the job is handled by a set of library functions, described in Table 3.3 (overleaf). These functions are defined in the cctype header.
ADVICE: USE THE C++(www.cppentry.com) VERSIONS OF C LIBRARY HEADERS
In addition to facilities defined specifically for C++(www.cppentry.com), the C++(www.cppentry.com) library incorporates the C library. Headers in C have names of the form name.h. The C++(www.cppentry.com) versions of these headers are named cname—they remove the .h suffix and precede the name with the letter c. The c indicates that the header is part of the C library.
Hence, cctype has the same contents as ctype.h, but in a form that is appropriate for C++(www.cppentry.com) programs. In particular, the names defined in the cname headers are defined inside the std namespace, whereas those defined in the .h versions are not.
Ordinarily, C++(www.cppentry.com) programs should use the cname versions of headers and not the name.h versions. That way names from the standard library are consistently found in the std namespace. Using the .h headers puts the burden on the programmer to remember which library names are inherited from C and which are unique to C++(www.cppentry.com).