function
<cwchar>

getwchar

wint_t getwchar (void);
Get wide character from stdin
Returns the next wide character from the standard input (stdin).

It is equivalent to calling getwc with stdin as argument.

This is the wide character equivalent of getchar (<cstdio>).

Parameters

(none)

Return Value

On success, the character read is returned (promoted to a value of type wint_t).
The return type is wint_t to accommodate for the special value WEOF, which indicates failure:
If the sequence of bytes read cannot be interpreted as a valid wide character, the function returns WEOF and sets errno to EILSEQ.
If the position indicator was at the end-of-file, the function returns WEOF and sets the eof indicator (feof) of stream.
If a reading error happens, the function also returns WEOF, but sets its error indicator (ferror) instead.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* getwchar example */
#include <stdio.h>
#include <wchar.h>

int main ()
{
  wint_t wc;
  fputws (L"Enter text. Include a dot (.) in a sentence to exit:\n",stdout);
  do {
    wc=getwchar();
    putwchar (wc);
  } while (wc != L'.');
  return 0;
}

A simple typewriter. Every sentence is echoed once ENTER has been pressed until a dot (.) is included in the text.

See also