Login    New User    Forgot Password    Help      

Stream

GO TO INDEX

What is a Stream?

A stream is the source or destination of a series of data, either characters, or in the case of binary files, a sequence of bytes that represent memory content. The standard input and output stream objects of C++ are declared in the header file iostream.


Standard Input Stream

Generally, the device used for input is the keyboard. For inputting, the keyword cin is used, which is an object. The operator of extraction, >>, is used on the standard input stream, in this case: cin stream. Syntax for using the standard input stream is cin followed by the operator >> followed by the variable that stores the data extracted from the stream.

Example

int prog;
cin >> prog;

In the example above, the variable prog is declared as an integer type variable. The next statement is the cin statement. The cin statement waits for input from the user"s keyboard that is then stored in the integer variable prog.

Standard Output Stream

A By default, the device used for output is the screen of the computer. For outputting values the keyword cout is used, which is an object. The insertion operator << is used on the standard output cout stream. The syntax for using the standard output stream is cout followed by the operator << followed by the value to be inserted or output by the insertion operator.

Example

int prog;
cin >> prog;
cout << prog;

In the above example, the variable prog is declared as an integer type variable. The next statement is the cin statement that waits for input from the user"s keyboard. This information is then stored in the integer variable prog.

GO TO INDEX