Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library


The C++ <cstdio> header provides generic file operation support and defines a number of functions with narrow and multibyte character input/output capabilities, and the <cwchar> header provides functions with wide character input/output capabilities. These functions are available to use in a current program after including the header file using - #include <cstdio> or #include <stdio.h>. Functions and macros of this header file are listed below:

Library Functions

Operations on files

FunctionsDescription
remove() Deletes a file.
rename() Renames a file.
tmpfile() Open a temporary file.
tmpnam() Generate temporary filename.

File access

FunctionsDescription
fclose() Closes a file.
fflush() Flush stream.
fopen() Opens a file.
freopen() Reopen stream with different file or mode.
setbuf() Set stream buffer.
setvbuf() Change stream buffering.

Formatted input/output

FunctionsDescription
fprintf() Writes formatted data to stream.
fscanf() Reads formatted data from stream.

Unformatted input/output

FunctionsDescription
fgetc() Gets character from stream.
fgets() Gets string from stream.
getc() Get character from stream.
getchar() Get character from stdin.
gets() Gets string from stdin.
fputc() Writes character to stream.
fputs() Writes string to stream.
putc() Writes character to stream.
putchar() Writes character to stdout.
puts() Writes string to stdout.
ungetc() Puts a character back into a file stream.

File positioning

FunctionsDescription
fgetpos() Gets the current file position indicator.
fseek() Moves the file position indicator to a specific location.
fsetpos() Sets the file position indicator to a specific location.
ftell() Returns the current file position indicator.
rewind() Sets the file position indicator to the beginning.

Error handling

FunctionsDescription
clearerr() Clear error indicators.
feof() Check end-of-file indicator.
ferror() Checks for a file error.

Library Types

TypesDescription
FILE Object type, capable of holding all information needed to control a stream.
fpos_t Object containing information to specify a position within a file.
size_t Unsigned integer type.

Library Macros

Predefined standard streams

MacrosDescription
stdin Expression of type FILE* associated with the input stream.
stdout Expression of type FILE* associated with the output stream.
stderr Expression of type FILE* associated with the error output stream.

Macro constants

MacrosDescription
BUFSIZ Buffer size.
EOF End-of-File.
FILENAME_MAX Maximum length of file names.
FOPEN_MAX Number of files that can be open simultaneously.
L_tmpnam Size needed for an array of char to hold the result of tmpnam().
NULL Null pointer.
TMP_MAX Maximum number of unique filenames that is guaranteed to be possible to generate using tmpnam().
SEEK_SET
SEEK_CUR
SEEK_END
Argument to fseek() indicating seeking from beginning of the file, from the current file position, and from end of the file respectively.

5