Home > Backend Development > C++ > 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
Release: 2023-09-11 17:57:07
forward
1437 people have browsed it

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 );
Copy after login

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);
Copy after login

Output

a
Copy after login

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;
}
Copy after login

Output

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

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;
}
Copy after login

Output

English Alphabets are: a b
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template