Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 Streams, Files

2 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 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 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 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 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 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 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 9 Stream


Download ppt "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."

Similar presentations


Ads by Google