A computer program can do two main things, ask for information or give the user new information.

This two concepts are input and output, and it’s what we are going to talk about in this post.

First, their definition:

Output:

Any information that has been processed by and sent out from a computer or similar device is considered output.

Input:

Any information or data that is sent to a computer for processing is considered input. Input or user input is most often sent to the computer using an input device such as a keyboard or mouse.

Input and Output example

Header Files:

To do input and output, you will need to load the iostream header file.

Like this:

#include <iostream>  // I/O

#include <fstream>   // file I/O

#include <iomanip>   // format manipulation

#include <string>

 

Which means that you’re confirming that your program will have the ability to receive and send information and manipulate it as you tell it to do it.

Streams:

There only exist 3 streams, which are:

Cout (terminal output)

Cin (Terminal input)

Cerr (error output) Mosly used for error messages.

Here are some code examples where you can see Cout and Cin:

#include <iostream>
using namespace std;

int main ()
{
  int v1, v2;
  int sum =0;

  cout<< "Please introduce the lower bound of the range:  ";
  cin>> v1;
  cout<< "Please introduce the higher bound of the range:  ";
  cin>> v2;

  int number =v1;
  while (number<=v2){
    sum= sum+number;
    number++;

  }
  cout<< "The inclusive sum is:  "<<sum<<endl;
  return 0;


}

I really hope this post can help to solve your doubts about Input/Output in C++, if you want to know more abot this I will let you the link of a really good page!

Once again, feel free to ask anything and I will be happy to answer.

Have a nice day!

-The Admin.