C++ Standard Library C++ STL Library

C++ <cwchar> - putwchar() Function



The C++ <cwchar> putwchar() function writes a wide character wc to the output stream stdout. It is equivalent to calling putwc() function with stdout as second argument.

If the wide character cannot be represented using the multibyte encoding, the function returns WEOF and sets errno to EILSEQ.

If a writing error occurs, the function returns WEOF and sets the error indicator for the stream ferror().

Syntax

wint_t putwchar (wchar_t wc);

Parameters

wc Specify a wide character to be written.

Return Value

On success, the character wc is returned. On writing error, returns WEOF and sets the error indicator ferror(). On encoding error, returns WEOF and sets errno to EILSEQ.

Example:

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

#include <cstdio>
#include <cwchar>

int main (){
  
  //prints wide characters
  for(wchar_t wc = L'A'; wc <= L'Z'; wc++)
    putwchar(wc);

  return 0;
}

The output of the above code will be:

ABCDEFGHIJKLMNOPQRSTUVWXYZ

❮ C++ <cwchar> Library