C++ putwchar()

The putwchar() function in C++ writes a wide character to stdout.

The putwchar() function is defined in <cwchar> header file.

putwchar() prototype

wint_t putwchar(wchar_t ch);

The putwchar() function takes a wide character to write it to stdout. A call to putwchar(ch) is equivalent to putwc(ch, stdout).

putwchar() Parameters

  • ch: The wide character to be written.

putwchar() Return value

  • On success, the putwchar() function returns the wide character represented by ch.
  • On failure, it returns WEOF.

Example: How putwchar() function works?

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

int main()
	setlocale(LC_ALL, "en_US.UTF-8");
	wchar_t start = L'\u05d0', end = L'\u05ea';
	wcout << L"Hebrew Alphabets" << endl;

	for (wchar_t i=start; i<=end; i++)
		putwchar(' ');
	return 0;

When you run the program, the output will be:

Hebrew Alphabets
א ב ג ד ה ו ז ח ט י ך כ ל ם מ ן נ ס ע ף פ ץ צ ק ר ש ת