CS212: Object Oriented Analysis and Design

Slides:



Advertisements
Similar presentations
CS-1030 Dr. Mark L. Hornick 1 IOStreams revisited Streams, strings, and files.
Advertisements

File I/O in C++. Using Input/Output Files A computer file is stored on a secondary storage device (e.g., disk);is stored on a secondary storage device.
1 Engineering Problem Solving With C++ An Object Based Approach Chapter 4 Programming with Data Files.
1 Lecture 31 Handling Selected Topics Again!! File I/O Special Lectures.
CS-212 C++ I/O Dick Steflik. C++ I/O Modeled after UNIX’s concept of a “stream” –conceptionally a stream is a continuous flow of characters/bytes from.
Input/Output Main Memory istream ostream Disk Drive Keyboard Scanner Disk Drive Monitor Printer stream = sequence of bytes.
C++ plus. 2 Goals Some general C++ tips 3 C++ Tips is header file for a library that defines three stream objects Keyboard an istream object named cin.
 Wednesday, 10/16/02, Slide #1 CS106 Introduction to CS1 Wednesday, 10/16/02  QUESTIONS??  Today:  Return and discuss Test #1  Input from and output.
How to Program in C++ CHAPTER 3: INPUT & OUTPUT INSTRUCTOR: MOHAMMAD MOJADDAM.
1 File I/O In C++, I/O occurs in streams. A stream is a sequence of bytes Each I/O device (e.g. keyboard, mouse, monitor, hard disk, printer, etc.) receives.
Streams, Files. 2 Stream Stream is a sequence of bytes Input stream In input operations, the bytes are transferred from a device to the main memory Output.
Stream Handling Streams - means flow of data to and from program variables. - We declare the variables in our C++ for holding data temporarily in the memory.
C++ Lecture 8 Monday, 25 August I/O, File, and Preprocessing l An in-depth review of stream input/output l File handling in C++ l C++ preprocessing.
1 Streams In C++, I/O occurs in streams. A stream is a sequence of bytes Each I/O device (e.g. keyboard, mouse, monitor, hard disk, printer, etc.) receives.
Chapter 14 Stream Input and Output By C. Shing ITEC Dept Radford University.
File handling in C++ BCA Sem III K.I.R.A.S. Using Input/Output Files Files in C++ are interpreted as a sequence of bytes stored on some storage media.
Chapter 9 Streams: Input stream: source of characters. Output stream: destination for characters. Up to now the input stream has defaulted to the keyboard.
FILE I/O IN C++. Using Input/Output Files A computer file  is stored on a secondary storage device (e.g., disk);  is permanent;  can be used to provide.
1 Simple Input/Output  C++ offers the iostream library, which defines a system of character-oriented Input/Output (I/O) using object oriented programming.
Lecture Contents I/O Streams. –Input/output streams. –Unformatted vs formatted streams. –Stream manipulators. –Stream error state. –Stream tying. –Examples.
1 I/O  C++ has no built-in support for input/output input/output is a library (iostream)  C++ program views input and output as a stream of bytes  Input:
 2000 Prentice Hall, Inc. All rights reserved. Chapter 21 - C++ Stream Input/Output Basics Outline 21.1Introduction 21.2Streams Iostream Library.
1 Today’s Objectives  Announcements Turn in Homework 4 Quiz 4 will be on Wednesday, July 19 – It will have questions about inheritance, polymorphism,
Chapter 11 Standard C++ Strings and File I/O Dept of Computer Engineering Khon Kaen University.
UNIT VI Streams & Files in C++: Stream classes, stream errors, disk file I/O with streams, File pointers, Error handling in file I/O. File I/O with members.
Chapter 3: Input/Output. Objectives In this chapter, you will: – Learn what a stream is and examine input and output streams – Explore how to read data.
1 COMS 261 Computer Science I Title: Functions Date: October 24, 2005 Lecture Number: 22.
File Handling in C++.
Engineering Problem Solving with C++, Second Edition, J. Ingber 1 Engineering Problem Solving with C++, Etter/Ingber Chapter 4 Working with Data Files.
Streams One of the themes of this course is that everything can be reduced to simple (and similiar) concepts. Streams are one example. Keyboard and Screen.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 9. Streams & Files.
File Processing Files are used for data persistance-permanent retention of large amounts of data. Computer store files on secondary storage devices,such.
CSCI 333 Data Structures I/O with C++ 20 October, 2003.
Lecture 14 Arguments, Classes and Files. Arguments.
Streams and File Processing in C++ Instructor - Andrew S. O’Fallon CptS 122 Washington State University.
File I/O in C++ I. Using Input/Output Files A computer file is stored on a secondary storage device (e.g., disk); is permanent; can be used to provide.
File I/O. Files allow permanent storage of programs and data. ifstream and ofstream objects –For file I/O the inclusion of is required. –Objects for file.
CS 1430: Programming in C++ 1. File Input in VS Project Properties Debugging Command Arguments quiz8-1.out We want to know how to do it ourselves, right?
1 Stream Input and Output Read Text, page Keyboard and Screen I/O #include cin (of type istream) cout (of type ostream) KeyboardScreen executing.
Ms N Nashandi Dr SH Nggada 2016/01/03Ms N Nashandi and Dr SH Nggada1 Week 6 -File input and output in C++
Computer Programming II Lecture 9. Files Processing - We have been using the iostream standard library, which provides cin and cout methods for reading.
Streams & Files in C++:Stream Classes, stream errors, disk file I/O with streams, File Pointers, Error handling in file I/O, File I/O with member functions,
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني I/O and File management Concept of streams. cin and cout objects. C++stream classes. Unformatted I/O.
Programming II I/O Streams and Data Files 1(c) Asma AlOsaimi.
Chapter 3: Input/Output. Objectives In this chapter, you will: – Learn what a stream is and examine input and output streams – Explore how to read data.
Introduction Every program takes some data as input and generate processed data as out put . It is important to know how to provide the input data and.
CS212: Object Oriented Analysis and Design
Introduction to C++ (Extensions to C)
Basic Input and Output Operations
week 1 - Introduction Goals
Review of Strings which include file needs to be used for string manipulation? what using statement needs to be included fro string manipulation? how is.
Data Streams.
Input and Output Chapter 3.
Basic File I/O and Stream Objects
IO Overview CSCE 121 J. Michael Moore
Programming with Data Files
when need to keep permanently
Review of Strings which include file needs to be used for string manipulation? what using statement needs to be included for string manipulation? how is.
Chapter 3: Input/Output
Standard Input/Output Stream
Managing console i/o operations
CSC 143 Stream I/O Classes and Files [A11-A15, A38-A50]
File I/O in C++ I.
File I/O.
ENERGY 211 / CME 211 Lecture 9 October 10, 2008.
IO Overview CSCE 121 Strongly influenced by slides created by Bjarne Stroustrup and Jennifer Welch.
Input/Output Streams, Part 1
File I/O in C++ I.
Introduction to Programming
Presentation transcript:

CS212: Object Oriented Analysis and Design Managing Input Output

Streams Input Stream Extraction from input stream Input device Program Output Stream Insertion into output stream Output device

Object Oriented Analysis and Design (CS 212) C++ stream class ios C++ provides various standard classes for I/O management File stream classes allows easy file handling File stream classes are declared in the fstream header file An object that belongs to a file stream class is known as a file stream istream ostream iostream ifstream ofstream fstream Object Oriented Analysis and Design (CS 212)

C++ predefined streams Meaning Device cin Standard input Keyboard cout Standard output Screen cerr Standard Error clog Buffered version of cerr Error checking in by cin Object Oriented Analysis and Design (CS 212)

Unformatted I/O Operation cin >> [istream] cout << [ostream] c = cin.get() cin.get(c) cout.put(c) cin.getline(line, size) [difference with cin ?] cout.write(line,size) Object Oriented Analysis and Design (CS 212)

Object Oriented Analysis and Design (CS 212) Formatted Console I/O ios class functions and flags Manipulators User defined output functions Object Oriented Analysis and Design (CS 212)

Examples of formatted console I/O cout.width(w) cout.precision(d) cout.fill(ch) Object Oriented Analysis and Design (CS 212)

Overloading << and >> << and the >> operators are overloaded in C++ to perform I/O for built-in types They can be overloaded to do the same for user-defined types << output operator is referred to as the insertion operator >> input operator is called the extraction operator Object Oriented Analysis and Design (CS 212)

Creating Own Inserters General form of inserter function Function returns a reference to a stream of type ostream First parameter to the function is a reference to the output stream Second parameter is the object being inserted ostream &operator <<(ostream &stream, class_type obj) { // body of inserter return stream; } Object Oriented Analysis and Design (CS 212)

Creating Own Extractors Extractors are the complement of inserters First parameter must also be a reference to a stream of type istream Second parameter must be a reference to an object of the class Function returns a reference to a stream of type istream istream &operator>>(istream &stream, class_type &obj) { // body of extractor return stream; } Object Oriented Analysis and Design (CS 212)

Creating Own Manipulator Functions It is possible to create custom manipulators Consolidate a sequence of several separate I/O operations into one manipulator I/O operations on a nonstandard device Demonstration Object Oriented Analysis and Design (CS 212)

Object Oriented Analysis and Design (CS 212) Functionality Inherit the functionality of their base classes Methods for non-formatted writing and reading of single characters and/or data blocks The operators << or >> for formatted reading and writing from or to files Methods and manipulators for formatting character sequences Object Oriented Analysis and Design (CS 212)