C++ iswblank()

The iswblank() function in C++ checks if the given wide character is a blank character or not.

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

iswblank() prototype

int iswblank(wint_t ch);

The iswblank() function checks if ch is a blank character or not as classified by the currently installed C locale.

By default, space and horizontal tab are considered as blank characters.


iswblank() Parameters

  • ch: The wide character to check.

iswblank() Return value

  • The iswblank() function returns non zero value if ch is a blank character.
  • It returns zero if ch is not a blank character.

Example: How iswblank() 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"\u0757\u077c\u0020\u00c5\u00d5\u00dd\u0009\u00a5";
	int count = 0;
	for (int i=0; i<wcslen(str); i++)
	{
		if (iswblank(str[i]))
		count ++;
	}

	wcout << L"Number of blank characters in \"" << str << "\" = " << count;
	return 0;
}

When you run the program, the output will be:

Number of blank characters in "ݗݼ ÅÕÝ¥" = 2