Basic Input
Basic Input
in C++
In C++, input and output are performed in the form of a sequence of bytes or more
commonly known as streams.
Input Stream: If the direction of flow of bytes is from the device (for example,
Keyboard) to the main memory then this process is called input.
Output Stream: If the direction of flow of bytes is opposite, i.e. from main memory
to device (display screen) then this process is called output.
All of these streams are defined inside the <iostream> header file which contains all
the standard input and output tools of C++. The two instances cout and cin of
iostream class are used very often for printing outputs and taking inputs respectively.
These two are the most basic methods of taking input and printing output in C++.
Standard Output Stream – cout
The C++ cout is the instance of the ostream class used to produce output on the standard output device which is
2
1
usually the display screen. The data needed to be displayed on the screen is inserted in the standard output stream
(cout) using the insertion operator(<<).
/ cout
int
Printing
return
main()
a <<
= 0;
22;
variable
a;{ 'a' using cout
}Syntax
cout << value/variable;
de
amespace
<iostream>
std;
Ex:
#include <iostream>
using namespace std;
int main() {
Output :
Explanation: In the above program, cout is used to output the text “GeeksforGeeks” to the standard output stream. It works in conjunction w
the insertion operator (<<) to send the specified data to the output stream.
We can also print the variable values using cout.