The Wayback Machine - https://web.archive.org/web/20250703074411/https://www.geeksforgeeks.org/putwchar-function-in-c-c/
Open In App

putwchar() function in C/C++

Last Updated : 14 Sep, 2018
Comments
Improve
Suggest changes
Like Article
Like
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 : CPP
// 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 : CPP
// 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

Next Article
Article Tags :
Practice Tags :

Similar Reads