iswalpha() function in C++ STL
Last Updated :
21 Aug, 2018
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:
#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;
}
|
Output:
Q is an alphabet
g is an alphabet
Program 2:
#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;
}
|
Output:
w is an alphabet
2 is not an alphabet
Share your thoughts in the comments
Please Login to comment...