Lecture 16 h.fileio.pdf - Introduction to Object-Oriented Programming COMP2011 File I\/O Prof Andrew Horner Dr Cecia Chan Dr Cindy Li Department of

Lecture 16 h.fileio.pdf - Introduction to Object-Oriented...

This preview shows page 1 - 5 out of 11 pages.

Introduction to Object-Oriented Programming COMP2011: File I/O Prof. Andrew Horner Dr. Cecia Chan Dr. Cindy Li Department of Computer Science & Engineering The Hong Kong University of Science and Technology Hong Kong SAR, China developed by Prof. Brian Mak { horner, kccecia, lixin } @cse.ust.hk COMP2011 (Spring 2018) p.1
Image of page 1
C++ Stream Up to now, you only know how to interactively input data from the keyboard using cin output data to the screen using cout In general, C++ allows you to input/output data to/from files and devices (e.g. printer, hard disk, USB memory stick) using an abstraction called stream . { horner, kccecia, lixin } @cse.ust.hk COMP2011 (Spring 2018) p.2
Image of page 2
C++ Stream C++ Stream A stream is simply a sequence of characters . The data transferred between a C++ program and a file/device are modeled as a stream of characters , regardless of the data type (basic types: int, float, etc.; user-defined types: btree, linked list, etc.). A device can also be treated like a file . In the following, when we say file, we mean both file and device. { horner, kccecia, lixin } @cse.ust.hk COMP2011 (Spring 2018) p.3
Image of page 3
Stream I/O Operations , To perform I/O, create a stream object (from various stream classes ) for each file. These stream objects all support the 2 basic input/output operators: , . Both and are implemented so that they convert input/output data of the required type from/to a sequence of characters .
Image of page 4
Image of page 5

You've reached the end of your free preview.

Want to read all 11 pages?

  • Spring '17
  • wert
  • stream, file stream, input file stream, Prof. Andrew Horner

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes