Translations of this page?:

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 stringstream class.

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

I/O Constructorsconstructors
badtrue if an error occurred
clearclear and set status flags
closeclose a stream
eoftrue if at the end-of-file
exceptionsset the stream to throw exceptions on errors
failtrue if an error occurred
fillmanipulate the default fill character
flagsaccess or manipulate io_stream_format_flags
flushempty the buffer
gcountnumber of characters read during last input
getread characters
getlineread a line of characters
goodtrue if no errors have occurred
ignoreread and discard characters
is_opencheck if a file is open
openopen a new stream
peekcheck the next input character
precisionmanipulate the precision of a stream
putwrite characters
putbackreturn characters to a stream
rdstatereturns the state flags of the stream
readread data into a buffer
seekgperform random access on an input stream
seekpperform random access on output streams
setfset format flags
sync_with_stdiosynchronize with standard I/O
tellgread input stream pointers
tellpread output stream pointers
unsetfclear io_stream_format_flags
widthaccess and manipulate the minimum field width
writewrite characters
• • • IndexRecent changesRSScc