C Basic Input Output: Cout, Cin, Cerr Example - JohnHau/mis GitHub Wiki

https://www.guru99.com/input-output-cplusplus.html

What are Streams in C++? C++ provides users with a number of libraries that they can use to perform input/output tasks. These tasks are done in the form of byte sequences, popularly called streams.

The streams are divided into two:

Types of streams Input Stream: This is a type of stream where the bytes flow from a device such as a keyboard to the main memory. Output Stream: This is a type of stream where the bytes flow in the opposite direction, that is, from main memory then to the device such as display screen. In this C++ tutorial you will learn:

What are Streams in C++? How do streams work? Function Table C++ Header files for Input/ Output std::cout std::cin std::cerr std::clog Error handling with IO streams:

image

C++ Header files for Input/ Output C++ provides three libraries that come with functions for performing basic input/out tasks. They include:

Iostream: It’s an acronym for standard input/output stream. This header file comes with definitions for objects like cin/ cout/cerr. Iomanip: It’s an acronym for input/output manipulators. The library comes with functions that can be used for the manipulation of streams. It contains definitions for objects like setw, setprecision, and others. Fstream: This is a header file for describing the file stream. It handles data that is read from file as input or that is written to a file, the output. The cin and cout keywords are very popular in C++. They are used for taking inputs and printing outputs, respectively. To use them, you must include iostream header file in your program. The reason is that they are defined in that header file. Failure to include the iostream header file will generate an error. This results from a failure by the C++ compiler to understand the meaning of the keywords.

The major objects defined in the iostream header file are cin, cout, cerr, and clog. Let’s discuss them.

image

image

image

image

image

image

image

image

Error handling with IO streams: To check whether a stream is valid or not, you can use it as a Boolean.

image

image