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.