The iswspace() function is defined in <cwctype> header file.
iswspace() prototype
int iswspace(wint_t ch);
The iswspace() function checks if ch is a whitespace character or not. By default, the the following characters are whitespace characters:
- space (0x20, ' ')
- form feed (0x0c, '\f')
- line feed (0x0a, '\n')
- carriage return (0x0d, '\r')
- horizontal tab (0x09, '\t')
- vertical tab (0x0b, '\v')
iswspace() Parameters
- ch: The wide character to check.
iswspace() Return value
- The iswspace() function returns non zero value if ch is a whitespace character.
- It returns zero if ch is not a whitespace character.
Example: How iswspace() function works?
#include <cwctype>
#include <iostream>
#include <cwchar>
#include <clocale>
using namespace std;
int main()
{
setlocale(LC_ALL, "en_US.UTF-8");
wchar_t str[] = L"<html>\n<head>\n\t<title>\u0939\u0947\u0932\u094b</title>\n</head>\n</html>";
wcout << L"Before removing whitespace characters" << endl;
wcout << str << endl << endl;
wcout << L"After removing whitespace characters" << endl;
for (int i=0; i<wcslen(str); i++)
{
if (!iswspace(str[i]))
wcout << str[i];
}
return 0;
}
When you run the program, the output will be:
Before removing whitespace characters <html> <head> <title>हेलो</title> </head> </html> After removing whitespace characters <html><head><title>हेलो</title></head></html>