C++ I/O

The <iostream> library automatically defines a few standard objects:

  • cout, an object of the ostream class, which displays data to the standard output device.
  • cerr, another object of the ostream class that writes unbuffered output to the standard error device.
  • clog, like cerr, but uses buffered output.
  • cin, an object of the istream class that reads data from the standard input device.

The <fstream> library allows programmers to do file input and output with the ifstream and ofstream classes.

C++ programmers can also do input and output from strings by using the String Stream class.

Some of the behavior of the C++ I/O streams (precision, justification, etc) may be modified by manipulating various io stream format flags.

Display all entries for C++ I/O on one page, or view entries individually:

I/O Constructors constructors
bad true if an error occurred
clear clear and set status flags
close close a stream
eof true if at the end-of-file
fail true if an error occurred
fill manipulate the default fill character
flags access or manipulate io stream format flags
flush empty the buffer
gcount number of characters read during last input
get read characters
getline read a line of characters
good true if no errors have occurred
ignore read and discard characters
open create an input stream
peek check the next input character
precision manipulate the precision of a stream
put write characters
putback return characters to a stream
rdstate returns the state flags of the stream
read read data into a buffer
seekg perform random access on an input stream
seekp perform random access on output streams
setf set format flags
sync_with_stdio synchronize with standard I/O
tellg read input stream pointers
tellp read output stream pointers
unsetf clear io stream format flags
width access and manipulate the minimum field width
write write characters