Open In App

putwchar() function in C/C++

Last Updated : 14 Sep, 2018
Improve
Improve
Like Article
Like
Save
Share
Report

The putwchar() function in C/C++ writes a wide character to stdout (standard output). It is defined in CPP library .

Syntax :

wint_t putwchar(wchar_t ch)

Parameter : The function accepts one mandatory parameter ch which specifies the wide character to be written.

Return value : The function returns two value as below:

  • This function returns the wide character represented by ch, on success
  • It returns WEOF and the error indicator is set if the writing error occurs

Below programs illustrate the above function:
Program 1 :




// C++ program to illustrate
// putwchar() function
  
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
    setlocale(LC_ALL, "en_US.UTF-8");
  
    // initiate the starting and
    // the last alphabet
    wchar_t first = L'\u05d0', last = L'\u05ea';
  
    wcout << L"All Hebrew Alphabets : ";
  
    // print all the alphabets
    for (wchar_t i = first; i <= last; i++) {
        putwchar(i);
        putwchar(' ');
    }
  
    return 0;
}


Output:

All Hebrew Alphabets : א ×? ×? ×? ×? ×? ×? ×? ×? ×? ×? ×? ×? ם ×? ×? ×  ס ×¢ ×£ פ ×¥ צ ק ר ש ת

Program 2 :




// C++ program to illustrate the
// putwchar() function
  
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
    wchar_t wc;
  
    // initializing the first
    // and last alphabets
    wchar_t first = 'A', last = 'Z';
  
    wcout << L"All English Alphabets : ";
  
    // print all the alphabets from
    // first to the last
    for (wc = first; wc <= last; ++wc) {
        putwchar(wc);
        putwchar(' ');
    }
  
    return 0;
}


Output:

All English Alphabets : A B C D E F G H I J K L M N O P Q R S T U V W X Y Z


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads