wint_t getwc (FILE* stream);
Get wide character from stream
Returns the wide character currently pointed by the internal position indicator of the specified stream. The internal position indicator is then advanced to the next wide character.
Because wide characters are represented by multibyte characters in external files, the function may involve reading several bytes from the file, which are interpreted as a single character as if mbrtowc was called with the stream's internal mbstate_t object.
If the sequence of bytes read cannot be interpreted as a valid multibyte character (or there were too few bytes available to compose a wide character), the function returns WEOF and sets EILSEQ as the value of errno.
If the stream is at the end-of-file when called, the function returns WEOF and sets the end-of-file indicator for the stream (feof).
If a read error occurs, the function returns WEOF and sets the error indicator for the stream (ferror).
getwc and fgetwc are equivalent, except that getwc may be implemented as a macro in some libraries. See getwchar for a similar function that reads directly from stdin.
This is the wide character equivalent of getc (<cstdio>).
- Pointer to a FILE object that identifies an input stream.
The stream shall not have an orientation yet, or be wide-oriented (the first i/o operation on a stream determines whether it is byte- or wide- oriented, see fwide).
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.
/* getwc example */
int main ()
FILE * pFile;
int n = 0;
wc = getwc (pFile);
if (wc == L'$') n++;
} while (wc != WEOF);
wprintf (L"The file contains %d dollar sign characters ($).\n",n);
This program reads an existing file called myfile.txt character by character and uses the n variable to count how many dollar characters ($) does the file contain.
- Get character from stream (function
- Write wide character to stream (function
- Read formatted data from stream (function