iswalpha() function in C++ STL

The iswalpha() is a built-in function in C++ STL which checks if the given wide character is an alphabet or not. It is defined within the cwctype header file of C++.

The following characters are alphanumeric:

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

Syntax:



int iswalpha(ch)

Parameter: The function accepts a single mandatory parameter ch which specifies the wide character which we have to check that if it is an alphabet or not.

Return Value: The function returns two values:

  • If the ch is an alphanumeric character, then a non-zero value is returned.
  • If it is not an alphanumeric character, then 0 is returned.

Below programs illustrate the above function.

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Program to illustrate
// iswalpha() function
#include <cwctype>
#include <iostream>
using namespace std;
  
int main()
{
  
    wchar_t ch1 = 'Q';
    wchar_t ch2 = 'g';
  
    iswalpha(ch1) ? wcout << ch1 
    << "is alphabet " : wcout << ch1
    << " is not alphabet ";
  
    wcout << endl;
    iswalpha(ch2) ? wcout << ch2 
    << " is an alphabet " : wcout << ch2
    << " is not an alphabet ";
  
    return 0;
}

chevron_right


Output:

Q is an alphabet 
g is an alphabet

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Program to illustrate
// iswalpha() function
#include <cwctype>
#include <iostream>
using namespace std;
  
int main()
{
  
    wchar_t ch1 = 'w';
    wchar_t ch2 = '2';
  
    iswalpha(ch1) ? wcout << ch1 << 
    " is alphabet " : wcout << ch1 
    << " is not alphabet ";
  
    wcout << endl;
    iswalpha(ch2) ? wcout << ch2 << 
    " is an alphabet " : wcout << ch2 
    << " is not an alphabet ";
  
    return 0;
}

chevron_right


Output:

w is an alphabet 
2 is not an alphabet


My Personal Notes arrow_drop_up

Budding Web DeveloperKeen learnerAverage CoderDancer&Social Activist

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.