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.

Slides:



Advertisements
Similar presentations
Chapter 10 Input/Output Streams
Advertisements

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.
Chapter 8: I/O Streams and Data Files. In this chapter, you will learn about: – I/O file stream objects and functions – Reading and writing character-based.
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.
Chapter 3: Input/Output
UNFORMATTED INPUT OUTPUT. Topics to be discussed……………….. overloaded operators >> and and
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.
C++ for Engineers and Scientists Second Edition Chapter 8 I/O File Streams and Data Files.
File I/O ifstreams and ofstreams Sections 11.1 &
C++ Introduction : C++ compilation. Visual Studio 2008 : Creating Command-Line Program.
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.
1 CS161 Introduction to Computer Science Topic #13.
FILE HANDLING IN C++.
File I/O 1 ifstreams and ofstreams Sections 11.1 & 11.2.
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.
CSE 332: C++ IO We’ve Looked at Basic Input and Output Already How to move data into and out of a program –Using argc and argv to pass command line args.
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.
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.
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.
Program Input and the Software Design Process ROBERT REAVES.
Input/Output. Objectives In this chapter you will: Learn what a stream is and examine input and output streams Explore how to use the input stream functions.
File Processing Files are used for data persistance-permanent retention of large amounts of data. Computer store files on secondary storage devices,such.
Declaring fstream Objects An istream object named cin connects program and keyboard An ostream object named cout connects the program and the screen These.
Exploring the C++ Stream Library Copyright 2006 Oxford Consulting, Ltd1 February IO Streams  IOStreams are part of the Standard C++ library.
Streams and File Processing in C++ Instructor - Andrew S. O’Fallon CptS 122 Washington State University.
24 4/11/98 CSE 143 Stream I/O [Appendix C]. 25 4/11/98 Input/Output Concepts  Concepts should be review!  New syntax, but same fundamental concepts.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved Today’s Lecture  I/O Streams  Console I/O  File I/O  Tools for File I/O  Sequential.
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.
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.
1 Stream Input and Output Read Text, page Keyboard and Screen I/O #include cin (of type istream) cout (of type ostream) KeyboardScreen executing.
CSE 232: Moving Data Within a C++ Program Moving Data Within a C++ Program Input –Getting data from the command line (we’ve looked at this) –Getting data.
Computer Programming II Lecture 9. Files Processing - We have been using the iostream standard library, which provides cin and cout methods for reading.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني 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
CS212: Object Oriented Analysis and Design
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.
Basic Input and Output Operations
Copyright © 2003 Pearson Education, Inc.
Chapter 2 part #3 C++ Input / Output
Data Streams.
File I/O.
IO Overview CSCE 121 J. Michael Moore
Programming with Data Files
Today’s Lecture I/O Streams Tools for File I/O
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.
CHAPTER 4 File Processing.
Chapter 2 part #3 C++ Input / Output
ifstreams and ofstreams
ENERGY 211 / CME 211 Lecture 9 October 10, 2008.
IO Overview CSCE 121 Strongly influenced by slides created by Bjarne Stroustrup and Jennifer Welch.
File I/O in C++ I.
Programming Fundamental-1
Presentation transcript:

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 The bytes are transferred from main memory to a device such as (display screen, printer, disk, n/w…)

3 Stream C++ contains different pre defined stream that automatically opened when a program begins its execution. Such as cin, cout …. cin represents input stream connect to input devices (object of istream) cout represents output stream connect to output devices (object of ostream)

4 Stream Class Classes dealing with the input and output of data are called stream classes. The class hierarchy is Ios ostream istream iostream ofstream ifstream fstream

5 Stream Class The mother of all base classes is ios. The class ios contains most of the actual I/O code. It is ios that keeps track of the error state of the stream. In addition the ios class converts data for display. It understands the format of the different types of numbers, how to output character strings, integers, floats..

6 Stream Classes Standard output, cout, is an object of the class ostream. Standard input, cin, is an object of the class istream. cout, and cin are automatically constructed as global objects at program start up. Objects of iostream deal with both input and output. Objects of ifstream deal with input files and Objects of ofstream deal with output files. Objects fstream deal with files that can write to and read from. ofstream, ifstream, and fstream are subclasses that are defined in the include le fstream.h

7 Stream Classes The overloaded right shift operator operator>>() is called the extractor. It is a member function of the class istream. The overloaded left shift operator operator<<() is called the inserter. It is a member function of the class ostream

8 Stream Classes Standard output (cout) Eg cout<<“hai”; int a=10; cout<<“value of a=“<<a; Inserter << is used to mix variables or strings Standard input (cin) Eg int a; cin>>a; The reading character for a variable will be terminated at the encounter of a white space or a character that does not match the destination type Let the following data is given as input 25D The operator will read the characters up to 5 and that value assign to a The character D remains in the input stream

9 Stream