Beruflich Dokumente
Kultur Dokumente
C++ STREAM
The I/O system supply and interface to the programmers i.e there is independence of actual devices being accessed. This interface is known as STREAM. A stream is a sequence of bytes which can be either I/P from a user or a O/P to be displayed.
DATA STREAM
PROGRAM
I/P STREAM
O/P STREAM
Output
21.254 Fill():It is used to fill a char in the unused portion of a field.
Setf():It is used to specify format flags that can control the form of output display. Unsetf():To clear the flags specified.
IOS
STREAM BUF
O/P
OSTREAM
IOSTREAM
ISTREAM_WITH ASSIGN
IOSTREAM_WITH ASSIGN
OSTREAM_WITH ASSIGN
The c++ IO system contains a hierarchy of classes that are used to define various streams to deal with both the console and disc files. These classes are called STREAM CLASSES. IOS is a base class for istream and ostream. The class IOS is declared as the VIRTUAL BASE CLASS. The class istream provides the facilities for formatted and unformatted i/p. The class ostream provides he facilities for formatted o/p.
The three classes namely istream_with assign, iostream_with assign and ostream_with assign add assignment operators to these classes. IOS :-streambuf-> Pointer to a buffer object. Istream:- get(), getline(), read() Ostream:- put(), write() Streambuf:- Provides an interface to physical devices through buffers.
Get()
Get(char*) Get(void) These are the 2 prototype to fetch a char including blank space, tab and a new line char. Get(char*) :Assigns the i/p char to its argument. Get(void) :Returns the i/p character.
Example
Char c; Cin.get(c); While(c!=\n) { Cout<<c; Cin.get(c); }
Put()
It is used to output a line of text character by character. It is a function of ostream. Syntax:cout.put(char/variable) Example cout.put(total);
Getline()
It reads a whole line of text that ends with a new line character. It is invoked by using the cin object. Syntax:cin.getline(line,size); cin.getline(name,20);
Write()
It is used to display the entire line. It is invoked by using object cout. Syntax:cout.write(line,size); cout.write(name,20);
MANIPULATORS
Manipulators are special function that can be included in the i/o statemants to alter the format parameters of a stream. Setw() Setprecession() Setfill() Setiosflags() Resetiosflags() to access these manipulators the file iomanip is included in the program.
Example
Ostream &unit(ostream & output) { output<<inches; output.setw(10); return output; } Void main() { Cout<<unit; Return 0; }
THANK YOU
PRESENTED BY V GROUP MITHRA KAVYA THANGAMANI KUMARESAN MANIKANDAN KRISHNAMOORTY LOGESHWARAN MAHAMOOD RIYAS