C++ is one of the most versatile languages in the world. It is used nearly everywhere for everything… systems programming (operating systems, device drivers, database engines, embedded, Internet of Things, etc.)

Enter Header Image Headline Here

Friday, 14 April 2017

C++ cout

                                              C++ cout


Cout: Display Output to user using Screen (Monitor)  

In c++ insertion operator is used to display value to the user. They value may be some message in the from of string or variable.

Important Point - 

" cout is a variable of type ostream.cin is a variable of type istream. "

Syntax : Dispaly Value to User 

cout << variable ;

Explanation : Insertion Operator

  • Include <iostream.h>header file to use cin.

#include <iostream.h>//traditional c++

or 

#include<iostream>//ANSI Standard
using namespace std;

  • cout is used for dispalying data on the screen.
  • The operator <<called as insertion operator or put to operator.
  • The Insertion operator can be overloaded.
  • Insertion operator is similar to the printf() operation in C.
  • cout is the object of ostream class.
  • Data flow direction is from variable to output device.
  • We can still use printf () for displaying an output.
  • Multipal output can be display using cout.


Live Example: Displaying Output on Screen


#include<iostream.h>
using namespace std;

int main ()
{
    int number1;
    int number2;

    cout<<"Enter First Number:";
    /* Display the message to tell the 
        user to do appropriate action */

    cin>>number1;
    cin>>number2;

    cout<<"Addition  : ";

    cout<<number1+number2; //Dispaly Result

    return 0;

}




0 comments:

Post a Comment

Popular Posts

Recent Posts

Categories

Unordered List

Text Widget