Related Articles

Related Articles

iswgraph() in C/C++ with Examples
  • Last Updated : 30 Aug, 2018

The iswgraph() is a built-in function in C/C++ which checks if the given wide character has an graphical representation or not. It is defined within the cwctype header file of C++. By default, the following characters are graphic:

  • Digits (0 to 9)
  • Uppercase letters (A to Z)
  • Lowercase letters (a to z)
  • Punctuation characters (!”#$%&'()*+, -./:;?@[\]^_`{|}~)

Syntax:

int iswgraph(ch)

Parameter: The function accepts a single mandatory parameter ch which specifies the wide character which we have to check that if it has a graphical representation or not.

Return Value: The function returns two values as shown below.

  • If the ch has a graphical representation character, then a non-zero value is returned.
  • If it is not a graphical representation character, then 0 is returned.

Below programs illustrates the above function.



Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate
// iswgraph() function
#include <cwctype>
#include <iostream>
using namespace std;
  
int main()
{
  
    wchar_t ch1 = '?';
    wchar_t ch2 = ' ';
  
    // Function to check if the character
    // has a graphical representation or not
    if (iswgraph(ch1))
        wcout << ch1 << " has graphical representation ";
    else
        wcout << ch1 << " does not have graphical representation ";
    wcout << endl;
  
    if (iswgraph(ch2))
        wcout << ch2 << " has graphical representation ";
    else
        wcout << ch2 << " does not have graphical representation ";
  
    return 0;
}

chevron_right


Output:

? has graphical representation 
  does not have graphical representation

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate
// iswgraph() function
#include <cwctype>
#include <iostream>
using namespace std;
  
int main()
{
  
    wchar_t ch1 = ' ';
    wchar_t ch2 = '3';
  
    // Function to check if the character
    // has a graphical representation or not
    if (iswgraph(ch1))
        wcout << ch1 << " has graphical representation ";
    else
        wcout << ch1 << " does not have graphical representation ";
    wcout << endl;
  
    if (iswgraph(ch2))
        wcout << ch2 << " has graphical representation ";
    else
        wcout << ch2 << " does not have graphical representation ";
  
    return 0;
}

chevron_right


Output:

does not have graphical representation 
3 has graphical representation

Attention reader! Don’t stop learning now. Get hold of all the important C++ Foundation and STL concepts with the C++ Foundation and STL courses at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up
Recommended Articles
Page :