C++ Standard Library C++ STL Library

C++ <cwctype> - iswgraph() Function



The C++ <cwctype> iswgraph() function is used to check if the given wide character has a graphical representation. A wide character with graphical representation are those characters than can be printed (as determined by iswprint() function) except the wide space character (L' '). In the default "C" locale, the following characters are graphic:

  • Digits (0123456789)
  • Uppercase letters (ABCDEFGHIJKLMNOPQRSTUVWXYZ)
  • Lowercase letters (abcdefghijklmnopqrstuvwxyz)
  • Punctuation characters (!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)

Other locales may consider a different selection of wide characters as graphic characters.

Syntax

int iswgraph ( wint_t ch );               

Parameters

ch Specify the wide character to be checked, casted to an wint_t, or WEOF.

Return Value

Returns non-zero value (i.e, true) if ch has a graphical representation, else returns zero (i.e, false).

Example:

The example below shows the usage of iswgraph() function.

#include <iostream>
#include <cwchar>
#include <cwctype>
using namespace std;
 
int main (){
  wchar_t str[50] = L"Hello \nWorld!";

  //replacing all wide characters which has no 
  //graphical representation with @ in str
  int i = 0;
  while(str[i]) {
    if(!iswgraph(str[i]))
      str[i] = L'@';
    i++;
  }

  //displaying the output
  wcout<<"str contains: "<<str;  
  return 0;
}

The output of the above code will be:

str contains: Hello@@World!

❮ C++ <cwctype> Library