Home  >  Article  >  Backend Development  >  In C/C++, the putwchar() function is a function used to output a wide character

In C/C++, the putwchar() function is a function used to output a wide character

WBOY
WBOYforward
2023-09-11 17:57:071415browse

In C/C++, the putwchar() function is a function used to output a wide character

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

What is putwchar()?

The putwchar() function is a built-in function in C STL, which is defined in the header file. The putwchar() function is used to write wide characters on the standard output device. This function takes the wide character from the argument and writes it to the system's stdout or standard output.

This function is the wide character version of putchar(), which is defined in the header file.

Syntax

putwchar( wchar_t widec );

Parameters

The function accepts the following parameters:

  • widec - We want to print in standard Wide characters on the output device.

Return value

This function returns two values:

  • If the wide character is successfully written to the standard output, the character written is returned.
  • If it fails, return WEOF and set the error indicator.

Example

Input

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

Output

a

Example

Example demonstration

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

Output

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

Example

Example demonstration

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

Output

English Alphabets are: a b

The above is the detailed content of In C/C++, the putwchar() function is a function used to output a wide character. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete