Input / Output (I/O) Functions in C++

What are Input / Output Functions in C++?
Types of Predefined I/O functions in C++


Character based Input / Output (I/O) functions supported by C++ are based on its predecessor C. All the functions supported by the C++ Standard Function Library are termed as ANSI C I/O system. To use these predefined I/O functions in a C++ program, the header file <cstdio.h> should be included.
Most of these functions set a built in global integer variable "errno" when an error is encountered. This variable stores the information about the error occured, so that it can be reffered by C++ programs.

Following table lists few character based predefined Input / Output(I/O) functions of C++ Standard function Library.
Name Description
scanf Reads the input from standard input.
fscanf Reads from the named input stream.
sscanf Reads the characters in the specified format.
printf Prints the output to the standard output.
sprintf Prints the output to the standard output.
fprintf Outputs the formatted output of argument values to the stream.
vprintf Formats and prints a series of characters and values to standard output.
vfprintf Formats and writes a series of characters, values to the output stream.
vsprintf Formats and stores a series of characters and values in the buffer target-string.
fopen Opens a file, then returns the stream associated.
freopen Associates an existing stream with a different file.
getc Returns the next character from input stream.
fgetc Gets the next character from the input stream, increments the file position indicator.
fgets Reads upto num-1 characters from the stream, places them to an array.
ungetc Returns the character specified by the low order byte.
putc Writes a character to the stream,at current position then advances the file position indicator.
fputc Writes a character to the stream,at current position then advances the file position indicator.
puts Writes a string to the standard output device.
clearerr Resets the error flag of a stream.
feof Checks the file position indicator to find the end of stream.
ferror Checks for the file error for the stream.
perror Prints an error message to stderr.
fflush Used to write the content of the output buffer to the file.
fgetpos Stores the current value of file position indicator.
fsetpos Moves the file position of the stream to a new location within the file.
fseek Sets the file-position indicator for the stream pointed to by stream.
fread Read the specified number of objects to place them in a array.
ftell Returns the current file position indicator for the current stream.
fwrite Writes from an array by counting the objects with the size to a stream.
rewind Moves the file position indicator to begining of the stream.
remove Used to erase the specified file.
tmpfile Opens a temporary file, then returns the pointer to the stream.
tmpnam Generates a unique filename then stores in an array.
setbuf Specifies the buffer used by the stream.

C++ Tutorial

Ask Questions

Ask Question