Classof1 logo
Fax: 1- 425- 458- 9358 | Toll free: 1- 877- 252 - 7763
Bookmark and Share
Forgot Password? Click Here
Register  |  Account

Need help with Computer Science assignment?

Get customized homework help now!

Streams

The data flow between the program and the console or files is called streams. There are two types of streams. They are

  • input stream
  • output stream

The flow of data from input device to program is called input stream. The flow of data from a program to output device is called output streams.

In C++ different streams are used to represent different types of data flow. Every stream is related with a class which contains its own member functions and the type of data flow.

All I/O stream classes are derived from a base class named as ios. This class is available in the header file iostream.h.

Unformatted I/O

1)Input operation:

The input operations are carried out using the following member function.

a)Overload operator >>

This operator is overloaded in the istream class and is used to give input from keyboard to program. General form:

Cin>>var1>>var2>>…..>>varn;

Where,Cin –    object
>> - operator
var1, var2,…….varn –    C++ variables already declared.

b)get( )

This function is used to input a single character to the program.This is a member function of istream class and is accessed with the help of the object cin.There are two types of

get( ) function.They are

get(char)

get(void)

get(char)

This function is used to assign the input character to its argument. General form:

Cin.get(variable_name);

Where variable_name –   character variable name.

Eg:char opt;

cin.get (opt);

get (void)

This function is used to assign the input character to the variable on the left hand side.

Syntax:

Variable_name = cin.get ( )

Eg:Char opt;

Opt = cin.get ()

c.getline( )

This function is used to input a line of text to the program. This is a member function of istream class and is accessed with the help of the object cin.

General form:

Cin.getline(variable_name, size);

Where size – number of character is the text plus one.The last place is used to store \0.

Variable_name -  valid c++ variable to store the data.

Eg:Char name[10];

Cin.getline(name,10);

2) Output operation:

The output operation is carried out using the following member functions.

a)overloaded operator <<

This operator is overloaded in the ostream class and is used to output data from program to VDU. Syntax:

Cout<< output list;

Where cout – object

<<   - operator

outputlist – the list of variables or constants.

Eg:X= 90;

Y= x +10;

Cout<<

Output: value of x and y are 90,100

b)put ( )

This function is used to output a single character from a program to the VDU. This is a member function of ostream class and is accessed with the help of the object cout. Syntax:

Cout.put (variable_name);

Where,

Variable_name – character variable name.

c)write( )

This function is used to output a line of text from program to VDU.This is a member function of ostream class and is accessed with the help of the object cout. General form:

Cout.write(variable_name, size);

Where, Size – number of characters to display.

Variable_name –  valid c++ variable and its represents the name of the string to be displayed.

Eg:Charname[10];

Cout.write(name,10);

Computer Science Homework Help
Name* :
Email* :
Country* :
Phone* :
Subject* :
Upload Homework :
Upload another homework (upto 5 uploads max.)
Due Date
Time
AM/PM
Timezone
Instructions
(Type Security Code - case sensitive)