C++ iswalpha()

The iswalpha() function in C++ checks if the given wide character is an alphabet or not.

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

iswalpha() prototype

int iswalpha(wint_t ch);

The iswalpha() function checks if ch is an alphabetic character or not. The following characters are classified as alphabets:

  • Uppercase letters: A to Z
  • Lowercase letters: a to z

iswalpha() Parameters

  • ch: The wide character to check.

iswalpha() Return value

  • The iswalpha() function returns non zero value if ch is an alphabetic character.
  • It returns zero, if ch is not an alphabetic character.

Example: How iswalpha() 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"\u221c!$131\u2288@";
	bool flag = 0;
	for (int i=0; i<wcslen(str); i++)
	{
		if (iswalpha(str[i]))
		{
			flag = 1;
			break;
		}
	}
	if (flag)
		wcout << str << L" contains alphabets";
	else
		wcout << str << L" doesn't contain alphabets";
		
	return 0;
}

When you run the program, the output will be:

∜!$131⊈@ doesn't contain alphabets