Console IO is essential for any program. It can be used to get user input, provide an output, and support debugging and diagnostics. A common cause of program instability also generally originates from poorly written IO, which is only exacerbated by the overuse of standard C printf()/scanf() IO functions. In this chapter, we will discuss the pros and cons of using C++ IO, commonly referred to as stream-based IO, compared to the standard C-style alternatives. In addition, we will provide a high-level introduction to C++ manipulators and how they can be used in place of standard C-style format strings. We will conclude this chapter with a set of examples designed to guide the reader through the use of both std::cout and std::cin.
The chapter has the following objectives:
- Learning about stream-based IO
- User-defined type-manipulators
- An...