putwchar() function in C/C++

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 :

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;
}

chevron_right


Output:

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

Program 2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;
}

chevron_right


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


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.