C / C ++中的isblank()
该函数isblank()用于检查传递的字符是否为空。它基本上是一个空格字符,并且还考虑了制表符(\t)。该函数在C语言的“ctype.h”头文件和C++语言的“cctype”头文件中声明。
这是isblank()C++语言的语法,
int isblank(int char);
这是isblank()C++语言的示例,
示例
#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++;
}
}