Cin and Cout in C - JohnHau/mis GitHub Wiki

https://iq.opengenus.org/cin-and-cout-in-cpp/ image

image

Headerfiles available in C++ for Input/Output Operations :

iostream - iostream stands for standard input-output stream. This header file contains definitions to objects like cin, cout, cerr etc. iomanip - iomanip stands for input output manipulators. The methods declared in this files are used for manipulating streams. This file contains definitions of setw, setprecision etc. fstream - This header file describes the file stream. This header file is used to handle the data being read from a file as input or data being written into the file as output. The objects being discussed in this article are cin and cout. They are the most commonly used objects for taking inputs and printing outputs.

Standard output stream (cout) cout is an object of the class ostream. The standard output device is the display screen. The characters are inserted into the output stream. The insertion operator (<<) is used along with cout to insert values into the stream so that the output device (monitor) can use them.

image

image

image

image

Output Formatting :

Formatting the output is an important part of any application, to improve the user interface and enhance the readability.

Formatting in C++ is done through the use of I/O manipulators. Most of these manipulators are available in iostream and iomanip.

The standard manipulators are :-

endl - Introduces a line break on the output stream similar to '\n'. The example was seen above .

setw() - The setw() manipulator sets the width of the field assigned for the output. It takes the size of the field (in number of characters) as argument.

image

image

image

image

image

image

image

image

image