[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/io/c [Back]  [Original]

C-style file input/output cppreference.com
cppreference.com

C-style file input/output

cppreference.com
< cpp | io


CI / O C + + C- / . <cstdio> / , <cwchar> / .
:
The C I/O subset of the C++ standard library implements C-style stream input/output operations. The <cstdio> header provides generic file operation support and supplies functions with narrow and multibyte character input/output capabilities, and the <cwchar> header provides functions with wide character input/output capabilities.
Google.
. .
C std::FILE, std::FILE* (: , std::FILE FILE*, / ). C (, , , , ..).
:
C streams are objects of type std::FILE that can only be accessed and manipulated through pointers of type std::FILE* (Note: while it may be possible to create a local object of type std::FILE by dereferencing and copying a valid FILE*, using the address of such copy in the I/O functions is undefined behavior). Each C stream is associated with an external physical device (file, standard input stream, printer, serial port, etc).
Google.
. .
C . / . C + + , , C : std::setlocale.
:
C streams can be used for both unformatted and formatted input and output. They are locale-sensitive and may perform wide/multibyte conversions as necessary. Unlike C++ streams, where each stream is associated with its own locale, all C streams access the same locale object: the one most recently installed with std::setlocale.
Google.
. .
, , (, POSIX), C :
:
Besides the system-specific information necessary to access the device (e.g. a POSIX file descriptor), each C stream object holds the following:
Google.
. .
1)
:
:
Character width: narrow or wide
Google.
. .
2)
: , , .
:
Buffering state: unbuffered, line-buffered, fully buffered.
Google.
. .
3)
, , .
:
The buffer, which may be replaced by an external, user-provided buffer.
Google.
. .
4)
I / O : , , ( ).
:
I/O mode: input, output, or update (both input and output).
Google.
. .
5)
Binary / .
:
Binary/text mode indicator.
Google.
. .
6)
.
:
End-of-file status indicator.
Google.
. .
7)
.
:
Error status indicator.
Google.
. .
8)
( std::fpos_t), , , ( mbstate_t).
:
File position indicator (an object of type std::fpos_t), which, for wide character streams, includes the parse state (an object of type mbstate_t).
Google.
. .

:
File access
Google.
. .
:
opens a file
Google.
. .

() []
:
open an existing stream with a different name
Google.
. .

() []
:
closes a file
Google.
. .

() []
:
synchronizes an output stream with the actual file
Google.
. .

() []
/ /
() []
:
sets the buffer for a file stream
Google.
. .

() []
:
sets the buffer and its size for a file stream
Google.
. .

() []
/
:
Direct input/output
Google.
. .
:
reads from a file
Google.
. .

() []
:
writes to a file
Google.
. .

() []
/
:
Unformatted input/output
Google.
. .
:
Narrow character
Google.
. .
:
gets a character from a file stream
Google.
. .

() []
:
gets a character string from a file stream
Google.
. .

() []
:
writes a character to a file stream
Google.
. .

() []

() []
stdin
:
reads a character from stdin
Google.
. .

() []
, stdin
:
reads a character string from stdin
Google.
. .

() []
stdout
:
writes a character to stdout
Google.
. .

() []
stdout
:
writes a character string to stdout
Google.
. .

() []
:
puts a character back into a file stream
Google.
. .

() []
:
Wide character
Google.
. .

() []

() []

() []

() []
stdin
() []
stdout
() []

() []
/
:
Formatted input/output
Google.
. .
/
:
Narrow/multibyte character
Google.
. .
stdin,
() []
(C++11)(C++11)(C++11)
stdin, buffer
:
reads formatted input from stdin, a file stream or a buffer
using variable argument list
Google.
. .

() []
stdout,
:
prints formatted output to stdout, a file stream or a buffer
Google.
. .

() []
stdout,

() []
:
Wide character
Google.
. .
stdin,
() []
(C++11)(C++11)(C++11)
stdin, ,
() []
stdout,
() []
stdout, ,
() []
:
File positioning
Google.
. .
:
returns the current file position indicator
Google.
. .

() []
:
gets the file position indicator
Google.
. .

() []
:
moves the file position indicator to a specific location in a file
Google.
. .

() []
:
moves the file position indicator to a specific location in a file
Google.
. .

() []
:
moves the file position indicator to the beginning in a file
Google.
. .

() []
:
Error handling
Google.
. .
:
clears errors
Google.
. .

() []
:
checks for the end-of-file
Google.
. .

() []
:
checks for a file error
Google.
. .

() []
, , stderr
() []
:
Operations on files
Google.
. .
:
erases a file
Google.
. .

() []
:
renames a file
Google.
. .

() []
,
:
creates and opens a temporary, auto-removing file
Google.
. .

() []
:
returns a unique filename
Google.
. .

() []

<cstdio>
Definition
FILE
, , CI / O
:
type, capable of holding all information needed to control a C I/O stream
Google.
. .
fpos_t
,
:
type, capable of uniquely specifying a position in a file
Google.
. .

<cstdio>
stdinstdoutstderr
FILE* stream
expression FILE*, stream
expression FILE*,
:
expression of type FILE* associated with the input stream
expression of type FILE* associated with the output stream
expression of type FILE* associated with the error output stream
Google.
. .

()
EOF
int
:
integer constant expression of type int and negative value
Google.
. .

()
FOPEN_MAX
,
:
number of files that can be open simultaneously
Google.
. .

()
FILENAME_MAX
:
size needed for an array of char to hold the longest supported file name
Google.
. .

()
BUFSIZ
, std::setbuf
:
size of the buffer used by std::setbuf
Google.
. .

()
_IOFBF_IOLBF_IONBF
std::setbuf / O
argument std::setbuf / O
argument std::setbuf I / O
:
argument to std::setbuf indicating fully buffered I/O
argument to std::setbuf indicating line buffered I/O
argument to std::setbuf indicating unbuffered I/O
Google.
. .

()
SEEK_SETSEEK_CURSEEK_END
std::fseek file
argument std::fseek position
argument std::fseek
:
argument to std::fseek indicating seeking from beginning of the file
argument to std::fseek indicating seeking from the current file position
argument to std::fseek indicating seeking from end of the file
Google.
. .

()
TMP_MAX
, std::tmpnam
:
maximum number of unique filenames that can be generated by std::tmpnam
Google.
. .

()
L_tmpnam
std::tmpnam
:
size needed for an array of char to hold the result of std::tmpnam
Google.
. .

()

Web Proxy Viewer  |  New URL  |  Original Page