﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-IT菜鸟-随笔分类-C++ Reference</title><link>http://www.cppblog.com/micwu/category/17016.html</link><description>启航</description><language>zh-cn</language><lastBuildDate>Tue, 31 May 2011 00:43:24 GMT</lastBuildDate><pubDate>Tue, 31 May 2011 00:43:24 GMT</pubDate><ttl>60</ttl><item><title>cctype (ctype.h)</title><link>http://www.cppblog.com/micwu/archive/2011/05/31/147732.html</link><dc:creator>micwu</dc:creator><author>micwu</author><pubDate>Tue, 31 May 2011 00:39:00 GMT</pubDate><guid>http://www.cppblog.com/micwu/archive/2011/05/31/147732.html</guid><wfw:comment>http://www.cppblog.com/micwu/comments/147732.html</wfw:comment><comments>http://www.cppblog.com/micwu/archive/2011/05/31/147732.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/micwu/comments/commentRss/147732.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/micwu/services/trackbacks/147732.html</trackback:ping><description><![CDATA[<p><strong>Character handling functions 字符处理</strong></p><span style="font-size: 10pt">This header declares a set of functions to classify and transform individual characters. </span><span style="font-size: 10pt">分类和转换</span><br /><br /><span style="font-size: 10pt">All these functions take as parameter the </span><tt><span style="font-size: 10pt">int</span></tt><span style="font-size: 10pt"> equivalent of one character and return an </span><tt><span style="font-size: 10pt">int</span></tt><span style="font-size: 10pt">, that can either be another character or a value representing a boolean value: 成功 != 0 ,失败 = 0</span><br /><span style="font-size: 10pt">an </span><tt><span style="font-size: 10pt">int</span></tt><span style="font-size: 10pt"> value of </span><tt><span style="font-size: 10pt">0</span></tt><span style="font-size: 10pt"> means false, and an </span><tt><span style="font-size: 10pt">int</span></tt><span style="font-size: 10pt"> value different from </span><tt><span style="font-size: 10pt">0</span></tt><span style="font-size: 10pt"> represents true.</span><br /><br /><span style="font-size: 10pt">There are </span><span style="font-size: 10pt; color: red">two sets of functions:</span><br /><span style="font-size: 10pt">First a set of </span><span style="font-size: 10pt">classifying </span><span style="font-size: 10pt">functions that check whether the character passed as parameter belongs to a certain category. These are:</span><br />
<table class="C_docLink">
<tbody>
<tr>
<td class="tit"><a href="http://www.cplusplus.com/reference/clibrary/cctype/isalnum/"><strong style="font-size: 10pt">isalnum</strong></a></td>
<td class="des"><span style="font-size: 10pt">Check if character is alphanumeric </span><span class="typ" style="font-size: 10pt">(function)&nbsp;&nbsp;&nbsp;文字字母</span></td></tr></tbody></table>
<table class="C_docLink">
<tbody>
<tr>
<td class="tit"><a href="http://www.cplusplus.com/reference/clibrary/cctype/isalpha/"><strong style="font-size: 10pt">isalpha</strong></a></td>
<td class="des"><span style="font-size: 10pt">Check if character is alphabetic </span><span class="typ" style="font-size: 10pt">(function)&nbsp;&nbsp;&nbsp;字母的 </span></td></tr></tbody></table>
<table class="C_docLink">
<tbody>
<tr>
<td class="tit"><a href="http://www.cplusplus.com/reference/clibrary/cctype/iscntrl/"><strong style="font-size: 10pt">iscntrl</strong></a></td>
<td class="des"><span style="font-size: 10pt">Check if character is a control character </span><span class="typ" style="font-size: 10pt">(function)&nbsp;&nbsp;&nbsp;控制符,like '\n'</span></td></tr></tbody></table>
<table class="C_docLink">
<tbody>
<tr>
<td class="tit"><a href="http://www.cplusplus.com/reference/clibrary/cctype/isdigit/"><strong style="font-size: 10pt">isdigit</strong></a></td>
<td class="des"><span style="font-size: 10pt">Check if character is decimal digit </span><span class="typ" style="font-size: 10pt">(function)&nbsp;&nbsp;&nbsp;数字</span></td></tr></tbody></table>
<table class="C_docLink">
<tbody>
<tr>
<td class="tit"><a href="http://www.cplusplus.com/reference/clibrary/cctype/isgraph/"><strong style="font-size: 10pt">isgraph</strong></a></td>
<td class="des"><span style="font-size: 10pt">Check if character has graphical representation </span><span class="typ" style="font-size: 10pt">(function)</span></td></tr></tbody></table>
<table class="C_docLink">
<tbody>
<tr>
<td class="tit"><a href="http://www.cplusplus.com/reference/clibrary/cctype/islower/"><strong style="font-size: 10pt">islower</strong></a></td>
<td class="des"><span style="font-size: 10pt">Check if character is lowercase letter </span><span class="typ" style="font-size: 10pt">(function)&nbsp;&nbsp;&nbsp;小写</span></td></tr></tbody></table>
<table class="C_docLink">
<tbody>
<tr>
<td class="tit"><a href="http://www.cplusplus.com/reference/clibrary/cctype/isprint/"><strong style="font-size: 10pt">isprint</strong></a></td>
<td class="des"><span style="font-size: 10pt">Check if character is printable </span><span class="typ" style="font-size: 10pt">(function)&nbsp;&nbsp;&nbsp;可打印字符,&nbsp;'\n'不可以&nbsp;</span></td></tr></tbody></table>
<table class="C_docLink">
<tbody>
<tr>
<td class="tit"><a href="http://www.cplusplus.com/reference/clibrary/cctype/ispunct/"><strong style="font-size: 10pt">ispunct</strong></a></td>
<td class="des"><span style="font-size: 10pt">Check if character is a punctuation character </span><span class="typ" style="font-size: 10pt">(function)</span></td></tr></tbody></table>
<table class="C_docLink">
<tbody>
<tr>
<td class="tit"><a href="http://www.cplusplus.com/reference/clibrary/cctype/isspace/"><strong style="font-size: 10pt">isspace</strong></a></td>
<td class="des"><span style="font-size: 10pt">Check if character is a white-space </span><span class="typ" style="font-size: 10pt">(function)</span></td></tr></tbody></table><span style="font-size: 8pt; color: #ff0000">standard white-space characters are:</span><br />
<table class="boxed">
<tbody>
<tr>
<td><tt><span style="font-size: 8pt">' '</span></tt></td>
<td><span style="font-size: 8pt">(0x20)</span></td>
<td><span style="font-size: 8pt">space (SPC)</span></td></tr>
<tr>
<td><tt><span style="font-size: 8pt">'\t'</span></tt></td>
<td><span style="font-size: 8pt">(0x09)</span></td>
<td><span style="font-size: 8pt">horizontal tab (TAB)</span></td></tr>
<tr>
<td><tt><span style="font-size: 8pt">'\n'</span></tt></td>
<td><span style="font-size: 8pt">(0x0a)</span></td>
<td><span style="font-size: 8pt">newline (LF)</span></td></tr>
<tr>
<td><tt><span style="font-size: 8pt">'\v'</span></tt></td>
<td><span style="font-size: 8pt">(0x0b)</span></td>
<td><span style="font-size: 8pt">vertical tab (VT)</span></td></tr>
<tr>
<td><tt><span style="font-size: 8pt">'\f'</span></tt></td>
<td><span style="font-size: 8pt">(0x0c)</span></td>
<td><span style="font-size: 8pt">feed (FF)</span></td></tr>
<tr>
<td><tt><span style="font-size: 8pt">'\r'</span></tt></td>
<td><span style="font-size: 8pt">(0x0d)</span></td>
<td><span style="font-size: 8pt">carriage return (CR)</span></td></tr></tbody></table><br />
<table class="C_docLink">
<tbody>
<tr>
<td class="tit"><a href="http://www.cplusplus.com/reference/clibrary/cctype/isupper/"><strong style="font-size: 10pt">isupper</strong></a></td>
<td class="des"><span style="font-size: 10pt">Check if character is uppercase letter </span><span class="typ" style="font-size: 10pt">(function)&nbsp;&nbsp;&nbsp;大写</span></td></tr></tbody></table>
<table class="C_docLink">
<tbody>
<tr>
<td class="tit"><a href="http://www.cplusplus.com/reference/clibrary/cctype/isxdigit/"><strong style="font-size: 10pt">isxdigit</strong></a></td>
<td class="des"><span style="font-size: 10pt">Check if character is hexadecimal digit </span><span class="typ" style="font-size: 10pt">(function)</span></td></tr></tbody></table><br /><span style="font-size: 10pt">And secondly, two functions to convert between letter cases:</span><br />
<table class="C_docLink">
<tbody>
<tr>
<td class="tit"><a href="http://www.cplusplus.com/reference/clibrary/cctype/tolower/"><strong style="font-size: 10pt">tolower</strong></a></td>
<td class="des"><span style="font-size: 10pt">Convert uppercase letter to lowercase </span><span class="typ" style="font-size: 10pt">(function)</span></td></tr></tbody></table>
<table class="C_docLink">
<tbody>
<tr>
<td class="tit"><a href="http://www.cplusplus.com/reference/clibrary/cctype/toupper/"><strong style="font-size: 10pt">toupper</strong></a></td>
<td class="des"><span style="font-size: 10pt">Convert lowercase letter to uppercase </span><span class="typ" style="font-size: 10pt">(function)</span></td></tr></tbody></table><br /><span style="font-size: 10pt">For the first set, here is a map of how the original 127-character ASCII set is considered by each function (an x indicates that the function returns true on that character)</span><br /><br />
<table class="boxed">
<tbody>
<tr>
<th><span style="font-size: 10pt">ASCII values</span></th>
<th><span style="font-size: 10pt">characters</span></th>
<th><a href="http://www.cplusplus.com/iscntrl"><span style="font-size: 10pt">iscntrl</span></a></th>
<th><a href="http://www.cplusplus.com/isspace"><span style="font-size: 10pt">isspace</span></a></th>
<th><a href="http://www.cplusplus.com/isupper"><span style="font-size: 10pt">isupper</span></a></th>
<th><a href="http://www.cplusplus.com/islower"><span style="font-size: 10pt">islower</span></a></th>
<th><a href="http://www.cplusplus.com/isalpha"><span style="font-size: 10pt">isalpha</span></a></th>
<th><a href="http://www.cplusplus.com/isdigit"><span style="font-size: 10pt">isdigit</span></a></th>
<th><a href="http://www.cplusplus.com/isxdigit"><span style="font-size: 10pt">isxdigit</span></a></th>
<th><a href="http://www.cplusplus.com/isalnum"><span style="font-size: 10pt">isalnum</span></a></th>
<th><a href="http://www.cplusplus.com/ispunct"><span style="font-size: 10pt">ispunct</span></a></th>
<th><a href="http://www.cplusplus.com/isgraph"><span style="font-size: 10pt">isgraph</span></a></th>
<th><a href="http://www.cplusplus.com/isprint"><span style="font-size: 10pt">isprint</span></a></th></tr>
<tr>
<td><span style="font-size: 10pt">0x00 .. 0x08</span></td>
<td><span style="font-size: 10pt">NUL, (other control codes)</span></td>
<td><span style="font-size: 10pt">x</span></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td></tr>
<tr>
<td><span style="font-size: 10pt">0x09 .. 0x0D</span></td>
<td><span style="font-size: 10pt">(white-space control codes: </span><tt><span style="font-size: 10pt">'\t'</span></tt><span style="font-size: 10pt">,</span><tt><span style="font-size: 10pt">'\f'</span></tt><span style="font-size: 10pt">,</span><tt><span style="font-size: 10pt">'\v'</span></tt><span style="font-size: 10pt">,</span><tt><span style="font-size: 10pt">'\n'</span></tt><span style="font-size: 10pt">,</span><tt><span style="font-size: 10pt">'\r'</span></tt><span style="font-size: 10pt">)</span></td>
<td><span style="font-size: 10pt">x</span></td>
<td><span style="font-size: 10pt">x</span></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td></tr>
<tr>
<td><span style="font-size: 10pt">0x0E .. 0x1F</span></td>
<td><span style="font-size: 10pt">(other control codes)</span></td>
<td><span style="font-size: 10pt">x</span></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td></tr>
<tr>
<td><span style="font-size: 10pt">0x20</span></td>
<td><span style="font-size: 10pt">space (</span><tt><span style="font-size: 10pt">' '</span></tt><span style="font-size: 10pt">)</span></td>
<td></td>
<td><span style="font-size: 10pt">x</span></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td><span style="font-size: 10pt">x</span></td></tr>
<tr>
<td><span style="font-size: 10pt">0x21 .. 0x2F</span></td>
<td><tt><span style="font-size: 10pt">!"#$%&amp;'()*+,-./</span></tt></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td><span style="font-size: 10pt">x</span></td>
<td><span style="font-size: 10pt">x</span></td>
<td><span style="font-size: 10pt">x</span></td></tr>
<tr>
<td><span style="font-size: 10pt">0x30 .. 0x39</span></td>
<td><tt><span style="font-size: 10pt">01234567890</span></tt></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td><span style="font-size: 10pt">x</span></td>
<td><span style="font-size: 10pt">x</span></td>
<td><span style="font-size: 10pt">x</span></td>
<td></td>
<td><span style="font-size: 10pt">x</span></td>
<td><span style="font-size: 10pt">x</span></td></tr>
<tr>
<td><span style="font-size: 10pt">0x3a .. 0x40</span></td>
<td><tt><span style="font-size: 10pt">:;&lt;=&gt;?@</span></tt></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td><span style="font-size: 10pt">x</span></td>
<td><span style="font-size: 10pt">x</span></td>
<td><span style="font-size: 10pt">x</span></td></tr>
<tr>
<td><span style="font-size: 10pt">0x41 .. 0x46</span></td>
<td><tt><span style="font-size: 10pt">ABCDEF</span></tt></td>
<td></td>
<td></td>
<td><span style="font-size: 10pt">x</span></td>
<td></td>
<td><span style="font-size: 10pt">x</span></td>
<td></td>
<td><span style="font-size: 10pt">x</span></td>
<td><span style="font-size: 10pt">x</span></td>
<td></td>
<td><span style="font-size: 10pt">x</span></td>
<td><span style="font-size: 10pt">x</span></td></tr>
<tr>
<td><span style="font-size: 10pt">0x47 .. 0x5A</span></td>
<td><tt><span style="font-size: 10pt">GHIJKLMNOPQRSTUVWXYZ</span></tt></td>
<td></td>
<td></td>
<td><span style="font-size: 10pt">x</span></td>
<td></td>
<td><span style="font-size: 10pt">x</span></td>
<td></td>
<td></td>
<td><span style="font-size: 10pt">x</span></td>
<td></td>
<td><span style="font-size: 10pt">x</span></td>
<td><span style="font-size: 10pt">x</span></td></tr>
<tr>
<td><span style="font-size: 10pt">0x5B .. 0x60</span></td>
<td><tt><span style="font-size: 10pt">[\]^_`</span></tt></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td><span style="font-size: 10pt">x</span></td>
<td><span style="font-size: 10pt">x</span></td>
<td><span style="font-size: 10pt">x</span></td></tr>
<tr>
<td><span style="font-size: 10pt">0x61 .. 0x66</span></td>
<td><tt><span style="font-size: 10pt">abcdef</span></tt></td>
<td></td>
<td></td>
<td></td>
<td><span style="font-size: 10pt">x</span></td>
<td><span style="font-size: 10pt">x</span></td>
<td></td>
<td><span style="font-size: 10pt">x</span></td>
<td><span style="font-size: 10pt">x</span></td>
<td></td>
<td><span style="font-size: 10pt">x</span></td>
<td><span style="font-size: 10pt">x</span></td></tr>
<tr>
<td><span style="font-size: 10pt">0x67 .. 0x7A</span></td>
<td><tt><span style="font-size: 10pt">ghijklmnopqrstuvwxyz</span></tt></td>
<td></td>
<td></td>
<td></td>
<td><span style="font-size: 10pt">x</span></td>
<td><span style="font-size: 10pt">x</span></td>
<td></td>
<td></td>
<td><span style="font-size: 10pt">x</span></td>
<td></td>
<td><span style="font-size: 10pt">x</span></td>
<td><span style="font-size: 10pt">x</span></td></tr>
<tr>
<td><span style="font-size: 10pt">0x7B .. 0x7E</span></td>
<td><tt><span style="font-size: 10pt">{|}~</span></tt></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td><span style="font-size: 10pt">x</span></td>
<td><span style="font-size: 10pt">x</span></td>
<td><span style="font-size: 10pt">x</span></td></tr>
<tr>
<td><span style="font-size: 10pt">0x7F</span></td>
<td><span style="font-size: 10pt">(DEL)</span></td>
<td><span style="font-size: 10pt">x</span></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td></tr></tbody></table><br /><span style="font-size: 10pt">The characters in the extended character set (above 0x7F) may belong to diverse categories depending on the locale and the platform. As a general rule, </span><a href="http://www.cplusplus.com/ispunct"><span style="font-size: 10pt">ispunct</span></a><span style="font-size: 10pt">, </span><a href="http://www.cplusplus.com/isgraph"><span style="font-size: 10pt">isgraph</span></a><span style="font-size: 10pt"> and </span><a href="http://www.cplusplus.com/isprint"><span style="font-size: 10pt">isprint</span></a><span style="font-size: 10pt"> return true on these for the standard C locale on most platforms support</span>ing extended character sets.<br /><br />ps:copy from C++ Reference <a href="http://www.cplusplus.com/reference/clibrary/cctype/">http://www.cplusplus.com/reference/clibrary/cctype/</a><br /><br /><img src ="http://www.cppblog.com/micwu/aggbug/147732.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/micwu/" target="_blank">micwu</a> 2011-05-31 08:39 <a href="http://www.cppblog.com/micwu/archive/2011/05/31/147732.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>