C/C++ 中的 iswgraph() 及其示例


在本文中,我們將討論 C++ STL 中 iswgraph () 函式的工作原理、語法和示例。

iswgraph() 是一個函式,屬於 <cwctype> 標頭檔案。此函式用於檢查給定的寬字元是否有任何圖形表示形式。該函式是函式 isgraph 的寬字元版本,該函式屬於 <cctype> 標頭檔案。

哪些寬字元具有圖形表示形式?

在螢幕上可以列印的所有寬字元都是具有圖形表示形式的字元。除了跳脫字元外,都是具有圖形表示形式的字元。

語法

int iswgraph(ch);

引數

該函式只接受一個引數,即寬字元型別 ch。

返回值

它返回一個整數值,即:如果寬字元不是圖形表示形式,則為 0;如果寬字元是圖形表示形式,則為非零值。

示例

Input: iswgraph(‘?’);
Output: It has a graphical representation.

Input: iswgraph(‘ ’);
Output: It doesn’t have a graphical representation.

示例

 即時演示

#include <cwctype>
#include <iostream>
using namespace std;
int main() {
   wchar_t ch_1 = '%';
   wchar_t ch_2 = ')';
   if(iswgraph(ch_1))
      wcout<< "It has graphical representation: "<<ch_1;
   else
      wcout<< "It doesn't have graphical representation: "<<ch_1;
   if (iswgraph(ch_2))
      wcout<< "\nIt has graphical representation: "<<ch_2;
   else
      wcout<< "\nIt doesn't have graphical representation: "<<ch_2;
   return 0;
}

輸出

如果我們執行上述程式碼,它將生成以下輸出 -

It has graphical representation: %
It has graphical representation: )

示例

 即時演示

#include <cwctype>
#include <iostream>
using namespace std;
int main() {
   wchar_t ch_1 = '9';
   wchar_t ch_2 = '/n';
   if(iswgraph(ch_1))
      wcout<< "It has graphical representation: "<<ch_1;
   else
      wcout<< "It doesn't have graphical representation: "<<ch_1;
   if (iswgraph(ch_2))
      wcout<< "\nIt has graphical representation: "<<ch_2;
   else
      wcout<< "\nIt doesn't have graphical representation: "<<ch_2;
   return 0;
}

輸出

如果我們執行上述程式碼,它將生成以下輸出 -

It has graphical representation: 9
It doesn't have graphical representation: ?

更新於:2020-03-23

90 瀏覽次數

事業起航

完成課程並獲得認證

開始
廣告
© . All rights reserved.