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++;
}
}热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志