Computer >> Computer tutorials >  >> Programming >> C programming

putwchar() function in C/C++


In this article we will be discussing the working, syntax and examples of putwchar() function in C++ STL.

What is putwchar()?

putwchar() function is an inbuilt function in C++ STL, which is defined in the <cwchar> header file. putwchar() function is used to write the wide character on the standard output device. This function takes the wide character from the arguments and writes it on the stdout or standard output of the system.

This function is a wide character version of putchar() which is defined in the <cstdio> header file.

Syntax

putwchar( wchar_t widec );

Parameters

The function accepts following parameter(s) −

  • widec − The wide character which we want to print on the standard output device.

Return value

This function returns two values −

  • If the wide character is successfully written on standard output, then the character is returned which is written.
  • If there is a failure then it returns WEOF and an error indicator is set.

Example

Input

wchar_t ch = ‘a’;
putwchar(ch);

Output

a

Example

#include <bits/stdc++.h>
using namespace std;
int main(){
   setlocale(LC_ALL, "en_US.UTF-8");
   wchar_t hold = L'\u05d0', next = L'\u05ea';
   wcout << L"Hebrew Alphabets are: ";
   for (wchar_t i = hold; i <= next; i++){
      putwchar(i);
      putwchar(' ');
   }
   return 0;
}

Output

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

Example

#include <bits/stdc++.h>
using namespace std;
int main(){
   wchar_t hold = 'a', next = 'b';
   wcout << "English Alphabets are: ";
   for (wchar_t i = hold; i <= next; ++i){
      putwchar(i);
      putwchar(' ');
   }
   return 0;
}

Output

English Alphabets are: a b