Compiling And Linking, C++ I/O statement, Input streams, Output streams

Compiling And Linking, C++ I/O statement, Input streams, Output streams Explain with examples



Compiling And Linking :

 Compiling and linking a C++ program depends on compiler and operating system.Turbo C++ and Borland C++ provide an integrated program development environment under MSDOS .They provide built in editor and a menu bar which includes options such as File, Edit, compile and Run.

C++ I/O statement:


C++ I/O operations are called streams. There are two types of streams in c++ they are                         1. Input streams             2. Output streams


Input streams: 

input streams are used to read data from input devices like keyboard, hard disc, etc. by using a predefined input stream object “cin” and “>>” extraction operator to read data from input devices.
    Syntax:     cin >> var;        example: cin >> x ;
           
For example in the above statement the compiler wait for input data for variable x the input data is then take from input device and then assigned to variable x. It is possible to read any type of data using cin statement.The header file iostream.h must be included to use this statement in a program.

Input cascading operation:
Input cascading means read values of more than one variable of different data types using single input statement.
    Syntax:      cin >> var1 >> var2>> var3;    
    Example:     cin >> x>>y>>z; //where x, y, z may be of different data type

Output streams: 

output streams are used to print data on output devices like monitor, discs etc. by using a predefined output stream object “cout “ and “<<” insertion operator to read data from output devices.
    Syntax:     cout << var;         example: cout << x;
       
For example in the above statement the compiler prints value of variable x on output device. It is possible to print any type of data using cout statement. The header file iostream.h must be included to use this statement in a program.

Output cascading operation:
Output cascading means print values of more than one variable of different data types using single output statement.
        Syntax         cout << var1 <<var2<<var3:
        Example     cout << x << y <<z; where x, y, z may be of different data type

Advantages of streams
1.    Streams do not require explicit data types specification in I/O statement
2.    Streams do not require explicit address operator prior to the variable in the input statement

Labels: