C/C++ 中的 isblank()
isblank() 函数用于检查传递的字符是否为空格符。它本质上是一个空格字符,还考虑制表符 (\t)。此函数在 C 语言中的“ctype.h”头文件中声明,在 C++ 语言的“cctype”头文件中声明。
下面是 C++ 语言中 isblank() 的语法:
int isblank(int char);
下面是 C++ 语言中 isblank() 的示例:
示例
#include <ctype.h>
#include <iostream>
using namespace std;
int main() {
string s = "The space between words. ";
int i = 0;
int count = 0;
while(s[i]) {
char c = s[i++];
if (isblank(c)) {
count++;
}
}
cout << "\nNumber of blanks in sentence : " << count << endl;
return 0;
}输出
Number of blanks in sentence : 4
在上面的程序中,一个字符串传递在变量 s 中。isblank() 函数用于检查所传递的字符串中的空格或空白,如下面的代码片段所示。
string s = "The space between words. ";
int i = 0;
int count = 0;
while(s[i]) {
char c = s[i++];
if (isblank(c)) {
count++;
}
}
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP