INPUT/OUTPUT Operators


The Standard Input Operator


  • ">>" also called stream extraction operator is used to get an input.
  • It is used with the standard input stream(cin).
  • It stores the input in a variable.
Example: Getting an input in a variable named "In".
cin>>In;

The Standard Output Operator


  • "<<" also called stream insertion operator is used to display output.
  • It is used with the standard output stream(cout).
  • It prints text or some valueon the output screen.
Example: Printing "Hello" on the screen.
cout<<"Hello";
Example: Printing a calculation.

cout<<2+7;   //Prints '9'
  • The difference comes out on the basis of use of quotes"".

Cascading of I/O Operators


  • Cascading refers to taking multiple inputs or outputs in a single line.
  • Multiple inputs takes place by placing ">>" between the different variable names.
  • Multiple outputs occur by placing "<<" between the different outputs.Mostly we need to separate the calculations part with the rest.
Example: Getting inputs in variables named "In" and "Put".
cin>>In>>Put;
Example: Printing "The Sum of 2 and 5 is 7.
cout<<"The Sum of 2 and 5 is "<<2+5;

See it all in a video:




Comments

Popular posts from this blog

Getting Started with C++

What is C++?

History Of C++