【正文】
ing in Part IV, but generally speaking, types related by inheritance share a mon interface. When one class inherits from another, we (usually) can use the same operations on both classes. More specifically, when two types are related by inheritance, we say that one class inherits the behavior the interface of its parent. In C++ we speak of the parent as the base class and the inheriting class as a derived class. The IO types are defined in three separate headers: iostream defines the types used to read and write to a console window, fstream defines the types used to read and write named files, and sstream defines the types used to read and write inmemory strings. Each of the types in fstream and sstream is derived from a corresponding type defined in the iostream header. Table lists the IO classes and Figure on the next page illustrates the inheritance relationships among these types. Inheritance is usually illustrated similarly to how a family tree is displayed. The topmost circle represents a base (or parent) class. Lines connect a base class to its derived (or children) class(es). So, for example, this figure indicates that istream is the base class of ifstream and istringstream. It is also the base class for iostream, which in turn is the base class for sstream and fstream classes. Because the types ifstream and istringstream inherit from istream, we already know a great deal about how to use these types. Each program we39。ve written that read an istream could be used to read a file (using the ifstream type) or a string (using the istringstream type). Similarly, programs that did output could use an ofstream or ostringstream instead of ostream. In addition to the istream and ostream types, the iostream header also defines the iostream type. Although our programs have not used this type, we actually know a good bit about how to use an iostream. The iostream type is derived from both istream and ostream. Being derived from both types means that an iostream object shares the interface of both its parent types. That is, we can use an iostream type to do both input and output to the same stream. The library also defines two types that inherit from iostream. These types can be used to read or write to a file or a string. Using inheritance for the IO types has another important implication: As we39。ll see in Chapter 15, when we have a function that takes a reference to a baseclass type, we can pass an object of a derived type to that function. This fact means that a function written to operate on istreamamp。 can be called with an ifstream or istring stream object. Similarly,a function that takes an ostreamamp。 can be called with an ofstream or ostring stream object. Because the IO types are related by inheritance, we can write one function and apply it to all three kinds of streams: console, disk files, or string streams. International Character Support The stream classes described thus far read and write streams posed of type char. The library defines a corresponding set of types supporting the wchar_t type. Each class is distinguished from its char counterpart by a w prefix. Thus, the types wostream, wistream, and wiostream read and write wchar_t data to or from a console window. The file input and output classes are wifstream, wofstream, and wfstream. The wchar_t versions of string stream input and output are wistring stream, wostring stream, and wstring stream. The library also defines objects to read and write wide characters from the standard input and standard output. These objects are distinguished from the char counterparts by a w prefix: The wchar_t standard input object is named wcin。 standard outp