
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
iswpunct Function in C++ STL
In this article we are going to discuss the iswpunct() function in C++, its syntax, working and its return values.
iswpunct() function is an inbuilt function in C++ which is defined in <cwctype> header file. The function checks whether the passed wide character is a punctuation character or not. This function is a wide character equivalent of ispunct(), which means it works the same as ispunct() the difference is it supports a wide character. So, the function checks if the argument passed is punctuation character then return any non zero integer value(true), else it will return zero(false)
Punctuation characters are as follows
! @ # $ % ^ & * ( ) “ ‘ , . / ; [ { } ] : ?
Syntax
int iswpunct(wint_t ch);
The function accepts only one parameter, i.e. a wide character which is to be checked. The argument is casted in wint_t or WEOF.
wint_t stores an integral type of data.
Return value
The function returns an integer value, which can be either 0 (in case of false) or any non-zero value(in case of true).
Example
#include <iostream> #include <cwctype> using namespace std; int main() { wint_t a = '.'; wint_t b = 'a'; wint_t c = '1'; iswpunct(a)?cout<<"\nIts Punctuation character":cout<<"\nNot Punctuation character"; iswpunct(b)?cout<<"\nIts Punctuation character":cout<<"\nNot Punctuation character"; iswpunct(c)?cout<<"\nIts Punctuation character":cout<<"\nNot Punctuation character"; }
Output
If we run the above code it will generate the following output −
Its Punctuation character Not Punctuation character Not Punctuation character
Example
#include <iostream> #include <cwctype> using namespace std; int main () { int i, count; wchar_t s[] = L"@tutorials, point!!"; count = i = 0; while (s[i]) { if(iswpunct(s[i])) count++; i++; } cout<<"There are "<<count <<" punctuation characters.\n"; return 0; }
Output
If we run the above code it will generate the following output −
There are 4 punctuation characters.