I/O Overview

​cin&cout

  • Standard in

    • Where input comes into a program by default

      • Normally the keyboard

      • Can be modified (e.g. pipes in UNIX)

  • Standard out

    • Where output is sent

      • Normally the screen

      • Can be modified (e.g. pipes)

  • Standard error

    • Where error messages are sent

      • Frequently set to a file

cin & cout
I/O
I/O

The Stream Model

An ostream
  • turns values of various types into character sequences

  • sends those characters somewhere (console, file, main memory, another computer…)

An istream
  • gets characters from somewhere (console, file, main memory, another computer,…)

  • turns character sequences into values of various types

The Stream Model

Supports reading and writing

  • of typed entities

    • << (output) and >> (input/extraction) plus other operations

    • type-safe

    • formatted

  • typically stored as text

    • but not necessarily, e.g, binary streams

  • extensible

    • define your own I/O operations for your own types

  • a stream can be attached to any I/O or storage device

Model

Last updated

Was this helpful?