C++ Standard Library C++ STL Library

C++ <cwctype> - wint_t Type



The C++ <cwctype> wint_t is an integer type that can hold any valid wide character and at least one more value (that corresponds to WEOF).

Some functions use this type to represent either a character of the wide character set or WEOF. This may be the same type as wchar_t or different depending on the system characteristics and library implementation.

This type is also defined in header <cwchar>.

Example:

The example below shows the usage of wint_t type.

#include <iostream>
#include <cwctype>
#include <cwchar>
using namespace std;
 
void try_widen(unsigned char c) {
  //wint_t type is used to hold the character 
  //value of the extended character set
  wint_t wc = btowc(c);
  
  //WEOF is used to check whether the widening of 
  //character was successful or not
  if(wc != WEOF)
    printf("Single-byte character %#x widens to %#x\n", c, wc);
  else
    printf("Single-byte character %#x failed to widen\n", c);
}

int main (){
  try_widen('A');
  try_widen('\t');
  try_widen(0xf9);
  try_widen(0xdf);
  return 0;
}

The output of the above code will be:

Single-byte character 0x41 widens to 0x41
Single-byte character 0x9 widens to 0x9
Single-byte character 0xf9 failed to widen
Single-byte character 0xdf failed to widen

❮ C++ <cwctype> Library