C++ cin and cout

C++ Standard Input/Output

C++ standard input/output operations are performed to flow bytes stream from keyboard (input device) to main memory and from main memory to display screen (output device) respectively. The input/output are done using standard libraries provided by C++.

C++ I/O Library Header Files

Library Description
<iostream> This library defines cin, cout, cerr,and clog objects for input stream, output stream, un-buffered error stream, buffered error stream respectively.
<fstream> This library defines file declares services for user-controlled file processing.
<iomapin> This library declares services useful for performing formatted I/O such as setw and setprecision.

C++ Standard Output Stream (cout)

C++ has predefined object cout. It is an instance of ostream class. The cout uses insertion or put to operator (<<) for printing output on screen like printf() function in C language. The multiple use of << in a single statement is called cascading.

Output:

C++ Standard Input Stream (cin)

C++ has predefined object cin. It is an instance of istream class. The cin uses extraction or get from operator (>>) to wait for user to provide input like scanf() function in C language. We can also cascade input operator >>.

Output:

Note: The endl keyword is used to move cursor to new line.