iswdigit() function in C/C++

The iswdigit() is a built-in function in C++ STL which checks if the given wide character is an decimal digit character or not. It is defined within the cwctype header file of C++. The characters from 0 to 9 i.e.0, 1, 2, 3, 4, 5, 6, 7, 8, 9 are classified as decimal digits.

Syntax:

int iswdigit(ch)

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

Return Value: The function returns two values as shown below.

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

Below programs illustrates the above function.

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate
// iswdigit() function
#include <cwctype>
#include <iostream>
using namespace std;
  
int main()
{
  
    wchar_t ch1 = '?';
    wchar_t ch2 = '3';
  
    // Function to check if the character
    // is a digit or not
    if (iswdigit(ch1))
        wcout << ch1 << " is a digit ";
    else
        wcout << ch1 << " is not a digit ";
    wcout << endl;
  
    if (iswdigit(ch2))
        wcout << ch2 << " is a digit ";
    else
        wcout << ch2 << " is not a digit ";
  
    return 0;
}

chevron_right


Output:

? is not a digit 
3 is a digit

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate
// iswdigit() function
#include <cwctype>
#include <iostream>
using namespace std;
  
int main()
{
  
    wchar_t ch1 = '1';
    wchar_t ch2 = 'q';
  
    // Function to check if the character
    // is a digit or not
    if (iswdigit(ch1))
        wcout << ch1 << " is a digit ";
    else
        wcout << ch1 << " is not a digit ";
    wcout << endl;
  
    if (iswdigit(ch2))
        wcout << ch2 << " is a digit ";
    else
        wcout << ch2 << " is not a digit ";
  
    return 0;
}

chevron_right


Output:

1 is a digit 
q is not a digit


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.