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