Monday 30 November 2015

Keyword cout and cin in C++ input output stream

Keyword cout and cin in C++ input output stream   In C++ to display/print something on the screen so we use the cout. Its syntax is ... thumbnail 1 summary

Keyword cout and cin in C++ input output stream

 

In C++ to display/print something on the screen so we use the cout.
Its syntax is very is just write cout then put << these symbols and then write inverted coma’s and then anything which you want to print then again inverted coma’s and then semi colon at the end of line.
cout<<”anything to print”;
But to print or display the values of variable just write cout and put << these symbols and then write the variable and put semi colon at the end and line.
For example
int a=4 ;
cout<<a;

What is cout in C++?



Note: 
In C++ at the end of every line in main() function you will put semi colon must.
Example 1
#include<iostream.h>
int main( )
{
cout<<”Hello world”;
return 0;
};
Example 2
#include<iostream.h>
int main( )
{
int a=5;
cout<<a;
return 0;
};
Example 3
#include<iostream.h>
int main( )
{
Char name[20]=”HaroonMuhammad”; 
int age =18;
float gpa= 3.10;
cout<<”My name is” ;
cout<<name;
cout<<”My  age is “;
cout<<age;
cout<<”My gpa is “;
cout<<gpa;
return 0;
};

What is cin in C++? 


cin is use in C++ to input the value of variables from the user. Its syntax is very easy just write cin and put >>these symbols and then write the variable which value you want to input from the user and put semi colon at the end of line.
int a;
cin>>a;
when the user enter some number so it will be automatic assign to the variable a. Note: In C++ at the end of every line in main() function you will put semi colon must.
Example 1
#include<iostream.h>
int main( )
{
int a;
cin>>a;
return 0;
};
Example 2
#include<iostream.h>
int main( )
{
int a;
cin>>a;
cout<<a;
return 0;
};
Example 3
#include<iostream.h>
int main( )
{
Char name[20]; 
int age ;
float gpa;
cout<<”please enter your name ” ;
cin>>name;
cout<<name;
cout<<”Enter your age “;
cin>>age;
cout<<age;
cout<<”Enter your gpa “;
cin>>gpa;
cout<<gpa;
return 0;
};