Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library


The C++ <cwchar> WEOF is a macro constant definition of type wint_t that expands into a constant expression whose value does not correspond to any character of wide character set.

It is used as the value returned by several wide character functions to indicate either the End-of-File has been reached, or to indicate a character value not corresponding to any member of the wide character set.

This macro constant is also defined in header <cwctype>.

Example:

The below example shows one of the usage of WEOF macro constant.

#include <iostream>
#include <cwchar>
using namespace std;
 
void try_widen(unsigned char c) {
  //wint_t type is used to hold the character 
  //value of the wide 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++ <cwchar> Library