ispunct <ctype.h> <cctype>

简介:

原文:http://www.cplusplus.com/reference/clibrary/cctype/ispunct/

int ispunct ( int c );
检查字符是否是标点符号

检查参数c是否是标点符号。任何一个不是字母或者数字(isalnum)的可显示字符(isgraph)都是一个标点符号。

想要得到不同的ctype函数在处理每个标准ANSII字符返回值的详细图表,请阅读参考<cctype>头文件。

在C++语言中,一个特定于语言环境模版版本的ispunct函数存在于头文件<locale>。

参数
c
 待检查字符,被转换成一个整数或者EOF结束符。
 
返回值
 如果事实上c是一个标点符号,返回值为非0(例如:true)。否则,返回值为0 (例如:false)。
 
实例

/* ispunct example */
#include <stdio.h>
#include <ctype.h>
int main ()
{
  int i=0;
  int cx=0;
  char str[]="Hello, welcome!";
  while (str[i])
  {
    if (ispunct(str[i])) cx++;
    i++;
  }
  printf ("Sentence contains %d punctuation characters.\n", cx);
  return 0;
}

输出:
Sentence contains 2 punctuation characters.

请参阅
isgraph 检测字符是否为可显示字符(函数)
iscntrl 检查字符是否是控制字符(函数)

相关文章
|
存储 算法 C++
C++中的字符串操作&lt;cstring&gt;和&lt;string&gt;的区别
目录 目录 参考资料 字符串 cstring和string的区别在哪 string类的实现 注意不要盲目相信以下内容! 不要盲目相信以下内容! 不要盲目相信以下内容! (重要的事情说三遍),虽然以下内容也经过了我的验证,但是我的验证可能有错误的地方,欢迎大家留言告知。
1279 0
实现string类的操作符重载 + = &gt; &lt; == != &gt;&gt; &lt;&lt;
<pre code_snippet_id="596931" snippet_file_name="blog_20150203_1_6205569" name="code" class="objc">//MyString.h #pragma once #include &lt;iostream&gt; using namespace std; class MyString { priva
1357 0