C++ STL 中的 iswcntrl() 函式
C++ 標準模板庫 (STL) 中的 iswcntrl() 函式用於檢查給定的寬字元是否是控制字元。控制字元在 C/C++ 中是不會在顯示屏上佔據列印位置的字元。iswcntrl() 函式是在 cwctype 標頭檔案中定義的。
iswcntrl() 函式的語法如下
int iswcntrl (wint_t c)
引數 − c − 這是要檢查的字元。
返回值 − 如果 c 是控制字元,則返回值與零不同(即非零值);否則,返回值為零。
下面程式中所採用的方法如下
- 從使用者那裡輸入字串或字元
- 遍歷迴圈,直到找到控制字元為止
- 顯示字串,直到找到第一個控制字元為止
- 當檢查到第一個控制字元時,退出迴圈
示例 1
#include <stdio.h>
#include <wctype.h>
int main (){
int i=0;
wchar_t str[] = L"first line \n second line \n";
while (!iswcntrl(str[i])) {
putchar (str[i]);
i++;
}
return 0;
}輸出
如果我們執行以上程式碼,它將生成以下輸出 −
First line
示例 2
#include <stdio.h>
#include <wctype.h>
int main (){
int i=0;
wchar_t str[] = L"first linesecond line \nthird line";
while (!iswcntrl(str[i])) {
putchar (str[i]);
i++;
}
return 0;
}輸出
如果我們執行以上程式碼,它將生成以下輸出 −
First linesecond line
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP