C++ Locale 库 - ispunct
描述
它检查字符是否是标点字符,并且其他语言环境可能会考虑选择不同的字符作为标点字符,但无论如何它们是 isgraph 而不是 isalnum。
声明
以下是 std::ispunct 的声明。
C++98
int ispunct ( int c );
C++11
int ispunct ( int c );
参数
c − 要检查、转换为 int 或 EOF 的字符。
返回值
它返回一个不同于零的值。
异常
No-throw guarantee − 此函数从不抛出异常。
示例
在下面的 std::ispunct 示例中。
#include <stdio.h>
#include <ctype.h>
int main () {
int i=0;
int cx=0;
char str[]="tutorialspoint india pvt ltd!";
while (str[i]) {
if (ispunct(str[i])) cx++;
i++;
}
printf ("Sentence contains %d punctuation characters.\n", cx);
return 0;
}
示例输出应该是这样的 −
Sentence contains 1 punctuation characters.

