C++ Input / Output

Input and output are the two main features of C++programming.  Standard input stream (cin) object is used to take input from the user.  Standard output stream (cout) object is used to print the output on the computer screen. The standard input-output stream (iostream) header file provides the definitions of cin, cout, etc.

Here we discuss each input/output object with examples


C++ Output

Cout along with the insertion operator “<<” is used to display the output on the screen.  Below is an example of C++ output.

//Output in C++
#include<iostream>
using namespace std;
int main()
{

cout << "Hellow World!" ;

}

Output

Hellow World!

C++ Input

Cin along with the extraction operator “>>” is used to take input from the user. Below is an example of C++ input.

//Output in C++
#include<iostream>
using namespace std;
int main()
{
 int a;
    cout << "Enter a number: "<<endl;
    cin>>a;
    cout<<"You enter: "<<a;
	
}

Output

Enter a number:
45
You enter: 45