
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
iswdigit Function in C++ STL
In C++ STL, iswdigit() function is a built-in function that is used to check if the given wide character is a decimal digit character or some other character. This function is present in a cwctype header file in C/C++.
What are the decimal digit characters?
Decimal digit character are the numeric values that starts from 0 i.e. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 .
Syntax of iswcntrl() function is as follows
int iswdigit() (wint_t c)
Parameters − c is a wide character to be checked, casted to a wint_t, or WEOF where wint_t is an integral type.
Return Value − A value different from zero (i.e., true) if indeed c is a decimal digit and value zero (i.e., false) otherwise.
Approach used in the below program is as follows
Input the string in a variable let’s say str[] of type string
Call the function iswdigit() to check whether the given wide character is a decimal digit or not
Print the result
Example-1
#include <cwctype> #include <iostream> using namespace std; int main(){ wchar_t c_1 = '2'; wchar_t c_2 = '*'; // Function to check if the character // is a digit or not if (iswdigit(c_1)) wcout << c_1 << " is a character "; else wcout << c_1 << " is a digit "; wcout << endl; if (iswdigit(c_2)) wcout << c_2 << " is a character "; else wcout << c_2 << " is a digit "; return 0; }
Output
If we run the above code it will generate the following output −
2 is a digit * is a character
Example-2
#include <stdio.h> #include <wchar.h> #include <wctype.h> int main (){ wchar_t str[] = L"1776ad"; long int year; if (iswdigit(str[0])) { year = wcstol (str,NULL,10); wprintf (L"The year that followed %ld was %ld.\n",year,year+1); } return 0; }
Output
If we run the above code it will generate the following output −
The year 1777 followed 1776