iswgraph() in C/C++ with Examples


In this article we will be discussing the working, syntax and examples of iswgraph() function in C++ STL.

iswgraph() is a function which comes under the <cwctype> header file. This function is used to check whether the given wide character has any graphical representation or not. The function is the wide character version of the function isgraph which comes under <cctype> header file.

Which wide characters have graphical representation?

All the wide characters which can be printed on screen are the those which are having a graphical representation. Except the escape characters are those which are having the graphical representation.

Syntax

int iswgraph(ch);

Parameters

The function accepts only one parameter which is ch, of wide character type.

Return value

It returns an integer value i.e. 0 is the wide character is not graphically represented and a nonzero value if the wide character is graphically represented.

Example

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

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

Example

 Live Demo

#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;
}

Output

If we run the above code it will generate the following output −

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

Example

 Live Demo

#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;
}

Output

If we run the above code it will generate the following output −

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

Updated on: 23-Mar-2020

72 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements