设为首页 加入收藏

TOP

3.2 Library string Type (5)
2013-10-07 16:19:05 来源: 作者: 【 】 浏览:66
Tags:3.2 Library string Type

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).

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇3.2 Library string Type (4) 下一篇3.2 Library string Type (6)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·用 Python 进行数据 (2025-12-25 15:49:09)
·如何学习Python数据 (2025-12-25 15:49:07)
·利用Python进行数据 (2025-12-25 15:49:04)
·Java 学习线路图是怎 (2025-12-25 15:19:15)
·关于 Java 学习,有 (2025-12-25 15:19:12)