I/O manipulators | ||||
Print functions(C++23) | ||||
C-style I/O | ||||
Buffers | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++20) | ||||
Streams | ||||
Abstractions | ||||
File I/O | ||||
String I/O | ||||
Array I/O | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
Synchronized Output | ||||
(C++20) | ||||
Types | ||||
Error category interface | ||||
(C++11) | ||||
(C++11) |
Types and objects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
Defined in header <cstdio> | ||
typedef/* unspecified */ FILE; | ||
Eachstd::FILE
object denotes a C stream.
C standard (referenced by C++ standard) does not specify whetherstd::FILE
is a complete object type. While it may be possible to copy a validstd::FILE
, using a pointer to such a copy as an argument for an I/O function invokes unspecified behavior. In other words,std::FILE
may be semantically non-copyable.
I/O streams can be used for both unformatted and formatted input and output. Furthermore, the functions that handle input and output can also be locale-sensitive, such that wide/multibyte conversions are performed as necessary.
Contents |
Besides the system-specific information necessary to access the device (e.g., a POSIX file descriptor), eachstd::FILE
object directly or indirectly holds the following:
A newly opened stream has no orientation. The first call tostd::fwide or to any I/O function establishes the orientation: a wide I/O function makes the stream wide-oriented; a narrow I/O function makes the stream narrow-oriented. Once set, the orientation can be changed with onlystd::freopen. Narrow I/O functions cannot be called on a wide-oriented stream; wide I/O functions cannot be called on a narrow-oriented stream. Wide I/O functions convert between wide and multibyte characters as if by callingstd::mbrtowc orstd::wcrtomb with the conversion state as described by the stream. Unlike the multibyte character strings that are valid in a program, multibyte character sequences in the file may contain embedded nulls and do not have to begin or end in the initial shift state.
The conversion state of a stream with wide orientation is established by the C locale that is installed at the time the stream's orientation is set.
Atext stream is an ordered sequence of characters that can be composed into lines; a line can be decomposed into zero or more characters plus a terminating'\n' (“newline”) character. Whether the last line requires a terminating'\n' is implementation-defined. Furthermore, characters may have to be added, altered, or deleted on input and output to conform to the conventions for representing text in the OS (in particular, C streams on Windows OS convert'\n' to'\r\n' on output, and convert'\r\n' to'\n' on input).
Data read in from a text stream is guaranteed to compare equal to the data that were earlier written out to that stream only if each of the following is true:
Abinary stream is an ordered sequence of characters that can transparently record internal data. Data read in from a binary stream always equal the data that were earlier written out to that stream, except that an implementation is allowed to append an indeterminate number of null characters to the end of the stream. A wide binary stream doesn't need to end in the initial shift state.
POSIX explicitly requires that theLC_CTYPE
facet of the currently installed C locale be stored within theFILE
object the moment the stream's orientation becomes wide; POSIX requires that thisLC_CTYPE
facet be used for all future I/O on this stream until the orientation is changed, regardless of any subsequent call tostd::setlocale.
It is intended that each line of text be composed of data that are essentially human-readable. POSIX implementations do not distinguish between text and binary streams (there is no special mapping for'\n' or any other characters).
abstracts a raw device (class template)[edit] | |
implements raw file device (class template)[edit] | |
expression of typeFILE* associated with the input stream expression of typeFILE* associated with the output stream expression of typeFILE* associated with the error output stream (macro constant)[edit] | |
C documentation forFILE |