C++ Standard Library C++ STL Library

C++ <cwctype> - iswpunct() Function



The C++ <cwctype> iswpunct() function is used to check if the given wide character is a punctuation character. In the default "C" locale, a punctuation character are all those graphic characters (as in iswgraph() function) which are not alphanumeric (as in iswalnum() function).

Other locales may consider a different selection of wide characters as punctuation characters.

Syntax

int iswpunct ( wint_t ch );               

Parameters

ch Specify the wide character to be checked, casted to an wint_t, or WEOF.

Return Value

Returns non-zero value (i.e, true) if ch is a punctuation character, else returns zero (i.e, false).

Example:

The example below shows the usage of iswpunct() function.

#include <iostream>
#include <cwchar>
#include <cwctype>
using namespace std;
 
int main (){
  wchar_t str[50] = L"Hello, World!";

  //replacing all wide punctuation 
  //characters with @ in str
  int i = 0;
  while(str[i]) {
    if(iswpunct(str[i]))
      str[i] = L'@';
    i++;
  }

  //displaying the output
  wcout<<"str contains: "<<str;  
  return 0;
}

The output of the above code will be:

str contains: Hello@ World@

❮ C++ <cwctype> Library