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

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.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 4- 1.
計算機概論實習 Stream Stream: sequence of bytes Input: from device (keyboard, disk drive) to memory Output: from memory to device (monitor, printer,
CSE 143 Lecture 18 Huffman slides created by Ethan Apter
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.
Program Input and the Software Design Process ROBERT REAVES.
28/08/2015SJF L31 F21SF Software Engineering Foundations ASSUMPTIONS AND TESTING Monica Farrow EM G30 Material available on Vision.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAM DESIGN WITH C++ Input/Output.
STREAMS AND FILES OVERVIEW.  Many programs are "data processing" applications  Read the input data  Perform sequence of operations on this data  Write.
Computer programming Lecture 4. Lecture 4: Outline Making Decisions [chap 6 – Kochan] –The if Statement –The if-else Construct –Logical Operators –Boolean.
What is an And Gate? It is a digital circuit that produce logical operations The logical operations are call Boolean logical Boolean operation consist.
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.
Copyright © 2002, Department of Systems and Computer Engineering, Carleton University CONTROL STRUCTURES Simple If: if (boolean exp) { statements.
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.
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.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 12: Advanced File Operations.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
CS162 External Data Files 1 Today in CS162 External Files What is an external file? How do we save data in a file?
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
ifstreams and ofstreams
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
Malwarebytes Settings and Configuration Issues
Control Structures – Selection
Input and Output Lecture 4.
File I/O.
Some Basics for Problem Analysis and Solutions
Computer Organization & Compilation Process
Stream States CSCE 121 J. Michael Moore
Lecture 5A File processing Richard Gesick.
Exceptions with Functions
Working with Data Files
Input Validation CSCE 121 J. Michael Moore
Conditions and Boolean Expressions
Topics Input and Output Streams More Detailed Error Testing
Chapter 12: Advanced File Operations.
Default Parameters February 24, 2016
Function Overloading CSCE 121 J. Michael Moore
Binary Numbers.
Chapter 10 Input/Output Streams
АВЛИГАТАЙ ТЭМЦЭХ ҮНДЭСНИЙ ХӨТӨЛБӨР /танилцуулга/
Learning Intention I will learn about the different types of programming errors.
ifstreams and ofstreams
Computer Organization & Compilation Process
References Revisted (Ch 5)
Input Validation CSCE 121 Based on slides created by Carlos Soto.
Programming Fundamental
Presentation transcript:

Stream States CSCE 121 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 This may or may not affect a future step of the computation, but it probably does (otherwise, what is the point of the variable?)

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 on 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