Stream States CSCE 121 J. Michael Moore

Slides:



Advertisements
Similar presentations
Slide: 1 Interra Induction Training Object Oriented Programming in C++ IO Streams Kolkata, July 25, 2005.
Advertisements

CSCE 121: Introduction to Program Design and Concepts Dr. J. Michael Moore Spring 2015 Set 7: Errors 1 Based on slides created by Bjarne Stroustrup.
Copyright © 2012 Pearson Education, Inc. Chapter 12: Advanced File Operations.
計算機概論實習 Stream Stream: sequence of bytes Input: from device (keyboard, disk drive) to memory Output: from memory to device (monitor, printer,
Copyright © 2012 Pearson Education, Inc. Chapter 5 Working with Data Files.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 27P. 1Winter Quarter I/O Manipulation Lecture.
28/08/2015SJF L31 F21SF Software Engineering Foundations ASSUMPTIONS AND TESTING Monica Farrow EM G30 Material available on Vision.
Chapter 10 Input/Output Streams John Keyser’s Modifications of Slides by Bjarne Stroustrup
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.
Advanced File Operations Chapter File Operations File: a set of data stored on a computer, often on a disk drive Programs can read from, write to.
File Input and Output in C++. Keyboard and Screen I/O #include cin (of type istream) cout (of type ostream) Keyboard Screen executing program input data.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 12: Advanced File Operations.
Making Decisions (True or False) Relational Operators >greater than =greater than or equal to
Slides adapted from: Bjarne Stroustrup, Programming – Principles and Practice using C++ Chapter 10 Input/Output Streams Hartmut Kaiser
The C++ Programming Language Streams. Contents u Output Stream u Input Stream u Formatting u Manipulators u Files & Streams.
CSC141- Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 31 Thanks for Lecture Slides: C How to Program by Paul Deital &
 2000 Prentice Hall, Inc. All rights reserved. Chapter 21 - C++ Stream Input/Output Basics Outline 21.1Introduction 21.2Streams Iostream Library.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 12 Advanced File Operations.
1 Today’s Objectives  Announcements Turn in Homework 4 Quiz 4 will be on Wednesday, July 19 – It will have questions about inheritance, polymorphism,
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2002, Department of Systems and Computer Engineering, Carleton University 1 INPUT STREAMS ifstream xin; // declares an input stream.
Looping ROBERT REVAES. Logical Operators  && AND  Both have to be true for it to evaluate to be true.  || OR  One or the other has to be true for.
ICS3U_FileIO.ppt File Input/Output (I/O)‏ ICS3U_FileIO.ppt File I/O Declare a file object File myFile = new File("billy.txt"); a file object whose name.
Engineering Problem Solving with C++, Second Edition, J. Ingber 1 Engineering Problem Solving with C++, Etter/Ingber Chapter 4 Working with Data Files.
CSCE 121: Introduction to Program Design and Concepts Dr. J. Michael Moore Spring Fall 2016 Set 10: Input/Output Streams 1 Based on slides created.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
Slides adapted from: Bjarne Stroustrup, Programming – Principles and Practice using C++ Chapter 10 Input/Output Streams Hartmut Kaiser
Advanced File Operations Chapter File Operations File: a set of data stored on a computer, often on a disk drive Programs can read from, write to.
Last week: We talked about: History of C Compiler for C programming
What is a File? A file is a collection on information, usually stored on a computer’s disk. Information can be saved to files and then later reused.
Huffman Coding Based on slides by Ethan Apter & Marty Stepp
Chapter 21 - C++ Stream Input/Output Stream Manipulators
Anatomy of a class Part II
Exceptions and files Taken from notes by Dr. Neil Moore
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Operator Overloading CSCE 121 J. Michael Moore
File I/O.
Iteration CSCE 121 J. Michael Moore.
Anatomy of a Function Part 2
Computer Organization & Compilation Process
Sorting CSCE 121 J. Michael Moore
Lecture 5A File processing Richard Gesick.
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Exceptions with Functions
Working with Data Files
Data Representation Bits
Manipulators CSCE 121 J. Michael Moore
Exceptions and files Taken from notes by Dr. Neil Moore
Return by Reference CSCE 121 J. Michael Moore.
Functions Overview CSCE 121 J. Michael Moore
Anatomy of a Function Part 3
Exceptions CSCE 121 J. Michael Moore
Input Validation CSCE 121 J. Michael Moore
Topics Input and Output Streams More Detailed Error Testing
Chapter 12: Advanced File Operations.
Function Overloading CSCE 121 J. Michael Moore
Anatomy of Inheritance
Inheritance in Graphics
Bingo Example: Design (Print Card Algorithm)
Destructor CSCE 121 J. Michael Moore.
Polymorphism & Pointers
Chapter 10 Input/Output Streams
Polymorphism & Pointers
Learning Intention I will learn about the different types of programming errors.
Computer Organization & Compilation Process
Input Validation CSCE 121 Based on slides created by Carlos Soto.
Stream States CSCE 121 Based on slides created by Carlos Soto.
Presentation transcript:

Stream States CSCE 121 J. Michael Moore Based on slides created by Carlos Soto.

Stream State State refers to the overall configuration of information. When you change a variable’s value, you change the state… OR not – sometimes the value of a variable does not alter what you would do!

What is the state of a stream? Good Location in file End of File Bad Problems with the stream itself Internet goes down Printer loses power Any kind of crash or break Input is not what is expected (Logical) Looking for an int got a ‘z’ Recall that all data in the files will be characters. Built in functions to convert strings to numbers, etc.

Robustness Recall that we want our programs to be robust. i.e. they should not crash with unexpected input! Streams store state information in flags (i.e. bits) We can use stream state information to recover gracefully when there are problems with streams.

Stream State Flags Flag Meaning goodbit Everything is OK eofbit Reached end of a file badbit Something is wrong with stream failbit Stream used incorrectly http://www.cplusplus.com/reference/ios/ios_base/iostate/

Stream State Functions eofbit failbit badbit good() eof() bad() fail() none of the bits set i.e. zero