Lecture overview -- Keyboard shortcut: 'u'  Previous page: The free store -- Keyboard shortcut: 'p'  Next page: Overloaded operators and IO -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 2 - Page 31 : 42
Notes about C++
Basic facilities
Input and output in C++

File IO - including standard input and standard output - is supported via the libraries ostream and istream

Overloading of the operators >> ('get from') and << ('put to') is used for textual input and output respectively

  • The C++ Programming Language: Page 607, 613
 

  • Considerations about IO in C++

    • IO functions must apply uniformly to pre-defined types and user-defined types

      • The C-style printf and scanf are not easy to generalize to user-defined functions

      • In addition, printf and scanf are not type safe

    • Use of overloaded functions, such as put(data) and get(data)

      • repetitive and tedious in real-life situtions

      • s.put(d1); s.put(d2); s.put(d3);     or

      • s.put(d1).put(d2).put(d3);

    • Use of overloaded operators seems attractive

      • Shorter, and easier to spot

      • s << d1 << d2 << d3