The iswprint() function is defined in <cwctype> header file.
iswprint() prototype
int iswprint(wint_t ch);
The iswprint() function checks if ch is printable or not. By default, the following characters are printable:
- Digits (0 to 9)
- Uppercase letters (A to Z)
- Lowercase letters (a to z)
- Punctuation characters (!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)
- Space
iswprint() Parameters
- ch: The wide character to check.
iswprint() Return value
- The iswprint() function returns non zero value if ch can be printed.
- It returns zero if ch cannot be printed.
Example: How iswprint() function works?
#include <cwctype>
#include <cwchar>
#include <iostream>
#include <clocale>
using namespace std;
int main()
{
setlocale(LC_ALL, "en_US.UTF-8");
wchar_t str[] = L"Ĥĕllö\tĂll\nĦow are ŷou";
for (int i=0; i<wcslen(str); i++)
{
/* replace all non printable character by hyphen */
if (!iswprint(str[i]))
str[i] = '-';
}
wcout << str;
return 0;
}
When you run the program, the output will be:
Ĥĕllö Ăll Ħow are ŷou
Here, \t and \n are non-printable characters in the string.