Open In App

iswalnum() function in C++ STL

Last Updated : 21 Aug, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report
The iswalnum() is a built-in function in C++ STL which checks if the given wide character is an alphanumeric character 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
  • Digits: 0 to 9
Syntax:
int iswalnum(ch)
Parameter: The function accepts a single mandatory parameter ch which specifies the wide character which we have to check that if it is alphanumeric or not. Return Value: The function returns two values as shown below.
  • If the ch is an alphanumeric character, then a non-zero value is returned.
  • If it is not then 0 is returned.
Below programs illustrates the above function. Program 1: CPP
// Program to illustrate
// iswalnum() function
#include <cwctype>
#include <iostream>
using namespace std;

int main()
{

    wchar_t ch1 = '?';
    wchar_t ch2 = 'g';

    // Function to check if the character
    // is alphanumeric or not
    if (iswalnum(ch1))
        wcout << ch1 << " is alphanumeric ";
    else
        wcout << ch1 << " is not alphanumeric ";
    wcout << endl;

    if (iswalnum(ch2))
        wcout << ch2 << " is alphanumeric ";
    else
        wcout << ch2 << " is not alphanumeric ";

    return 0;
}
Output:
? is not alphanumeric 
g is alphanumeric
Program 2: CPP
// Program to illustrate
// iswalnum() function
#include <cwctype>
#include <iostream>
using namespace std;

int main()
{

    wchar_t ch1 = '3';
    wchar_t ch2 = '&';

    // Function to check if the character
    // is alphanumeric or not
    if (iswalnum(ch1))
        wcout << ch1 << " is alphanumeric ";
    else
        wcout << ch1 << " is not alphanumeric ";
    wcout << endl;

    if (iswalnum(ch2))
        wcout << ch2 << " is alphanumeric ";
    else
        wcout << ch2 << " is not alphanumeric ";

    return 0;
}
Output:
3 is alphanumeric 
& is not alphanumeric

Next Article
Article Tags :
Practice Tags :

Similar Reads