Standard C++ Library Reference ISO/IEC (VERSION3)

which can have a broad range of encoding rules. (Text and binary files are still read and written
as described above.) Within the program, the stream looks like the corresponding sequence of
wide characters. Conversions between the two representations occur within the Standard C
library. The conversion rules can, in principle, be altered by a call to setlocale that alters
the category LC_CTYPE. Each wide stream determines its conversion rules at the time it
becomes wide oriented, and retains these rules even if the category LC_CTYPE subsequently
changes.
Positioning within a wide stream suffers the same limitations as for text streams. Moreover, the
file-position indicator may well have to deal with a state-dependent encoding. Typically, it
includes both a byte offset within the stream and an object of type mbstate_t. Thus, the only
reliable way to obtain a file position within a wide stream is by calling fgetpos, and the only
reliable way to restore a position obtained this way is by calling fsetpos.
Controlling Streams
fopen returns the address of an object of type FILE. You use this address as the stream
argument to several library functions to perform various operations on an open file. For a byte
stream, all input takes place as if each character is read by calling fgetc, and all output takes
place as if each character is written by calling fputc. For a wide stream (with Amendment 1),
all input takes place as if each character is read by calling fgetwc, and all output takes place
as if each character is written by calling fputwc.
You can close a file by calling fclose, after which the address of the FILE object is invalid.
A FILE object stores the state of a stream, including:
an error indicator -- set nonzero by a function that encounters a read or write error
an end-of-file indicator -- set nonzero by a function that encounters the end of the file
while reading
a file-position indicator -- specifies the next byte in the stream to read or write, if the file
can support positioning requests
a stream state -- specifies whether the stream will accept reads and/or writes and, with
Amendment 1, whether the stream is unbound, byte oriented, or wide oriented
a conversion state -- remembers the state of any partly assembled or generated
generalized multibyte character, as well as any shift state for the sequence of bytes in the
file)
a file buffer -- specifies the address and size of an array object that library functions can
use to improve the performance of read and write operations to the stream
Do not alter any value stored in a FILE object or in a file buffer that you specify for use with
that object. You cannot copy a FILE object and portably use the address of the copy as a