C++ iswgraph()

The iswgraph() function in C++ checks if the given wide character has a graphical representation or not.

The iswgraph() function is defined in <cwctype> header file.

iswgraph() prototype

int iswgraph(wint_t ch);

The iswgraph() function checks if ch has a graphical representation as classified by the current C locale. By default, the following characters are graphic:

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

iswgraph() Parameters

  • ch: The wide character to check.

iswgraph() Return value

  • The iswgraph() function returns non zero value if ch has a graphical representation character.
  • It returns zero if ch has no graphical representation character.

Example: How iswgraph() function works?

#include <cwctype>
#include <iostream>
#include <clocale>
using namespace std;

int main()
{
	setlocale(LC_ALL, "en_US.UTF-8");
	wchar_t ch1 = L'\u0009';
	wchar_t ch2 = L'\u03a9';
	
	iswgraph(ch1)? wcout << ch1 << L" has graphical representation" : wcout << ch1 << L" does not have graphical representation";
	wcout << endl;
	iswgraph(ch2)? wcout << ch2 << L" has graphical representation" : wcout << ch2 << L" does not have graphical representation";

	return 0;
}

When you run the program, the output will be:

 	 does not have graphical representation
Ω has graphical representation