Line 8 shows how a variable of name InputNumber is declared to store data of type int.The user is requested to enter a number using cout in Line 10, and the entered number is stored in the integer variable using cin in Line 13. The same exercise is repeated with storing the user’s name, which of course cannot be held in an integer but in a different type called string as seen in.
C++ I/O operation is using the stream concept. Stream is the sequence of bytes or flow of data. It makes the performance fast.
If bytes flow from main memory to device like printer, display screen, or a network connection, etc, this is called as output operation.
If bytes flow from device like printer, display screen, or a network connection, etc to main memory, this is called as input operation.
Let us see the common header files used in C++ programming are:
Header File | Function and Description |
---|---|
<iostream> | It is used to define the cout, cin and cerr objects, which correspond to standard output stream, standard input stream and standard error stream, respectively. |
<iomanip> | It is used to declare services useful for performing formatted I/O, such as setprecision and setw. |
<fstream> | It is used to declare services for user-controlled file processing. |
The cout is a predefined object of ostream class. It is connected with the standard output device, which is usually a display screen. The cout is used in conjunction with stream insertion operator (<<) to display the output on a console
Let's see the simple example of standard output stream (cout): Ts808 clone vst download.
Output:
The cin is a predefined object of istream class. It is connected with the standard input device, which is usually a keyboard. The cin is used in conjunction with stream extraction operator (>>) to read the input from a console.
Let's see the simple example of standard input stream (cin):
Output:
The endl is a predefined object of ostream class. It is used to insert a new line characters and flushes the stream.
Let's see the simple example of standard end line (endl):
Output: