C++ Standard Library C++ STL Library

C++ <cwctype> - iswprint() Function



The C++ <cwctype> iswprint() function is used to check if the given wide character is a printable character. A printable character is a character that occupies a printing position on a display. In the default "C" locale, a printable character are those having ASCII code greater than 0x1f (US), except 0x7f (DEL).

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

Syntax

int iswprint ( 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 is a printable character, else returns zero (i.e, false).

Example:

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

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

  //replacing all wide non-printable 
  //characters with @ in str
  int i = 0;
  while(str[i]) {
    if(!iswprint(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

5