13.1 Introduction

This chapter discusses a range of capabilities sufficient for performing most common input/output operations and overviews the remaining capabilities. We’ve already demonstrated I/O with string objects in earlier chapters and discuss it in more detail in Chapter 21. The string processing demonstrated in this chapter focuses on char* strings. In earlier chapters, we introduced various I/O features—here we provide a more complete treatment.

C++ uses type-safe I/O. Each I/O operation is executed in a manner sensitive to the data type. If an I/O function has been defined to handle a particular data type, then that function is called to handle that data type. If there is no match between the type of the actual data and a function for handling that data type, the compiler generates an error. Thus, improper data cannot “sneak” through the system (as can occur in C, allowing for some subtle and bizarre errors).

As you saw in Chapter 10, you can specify how to perform I/O for objects of user-defined types by overloading the stream insertion operator (<<) and the stream extraction operator (>>).

Error-Prevention Tip 13.1

C++ I/O is type safe.

 

Software Engineering Observation 13.1

C++ enables a common treatment of I/O for predefined types and user-defined types. This commonality facilitates software development and reuse.

 

Software Engineering Observation 13.2

In C++ programs, prefer C++-style I/O to C-style I/O.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset