C++ iswpunct()

The iswpunct() function in C++ checks if the given wide character is a punctuation or not.

The iswpunct() function is defined in <cwctype> header file.

iswpunct() prototype

int iswpunct(wint_t ch);

The iswpunct() function checks if ch is a punctuation character or not. By default, the punctuation characters are

!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~.

iswpunct() Parameters

  • ch: The wide character to check.

iswpunct() Return value

  • The iswpunct() function returns non zero value if ch is a punctuation character.
  • It returns zero if ch is not a punctuation character.

Example: How iswpunct() function works?

#include <cwctype>
#include <iostream>
#include <clocale>
using namespace std;

int main()
{
	setlocale(LC_ALL, "en_US.UTF-8");
	wchar_t ch1 = L'\u0938';
	wchar_t ch2 = L'\u007e';
	
	iswpunct(ch1) ? wcout << ch1 << L" is a punctuation character" : wcout << ch1 << L" is not a punctuation character";
	wcout << endl;
	iswpunct(ch2) ? wcout << ch2 << L" is a punctuation character" : wcout << ch2 << L" is not a punctuation character";
	
	return 0;
}

When you run the program, the output will be:

स is not a punctuation character
~ is a punctuation character