The first question is: Which of the standard stream classes shall be the base class? The answer fully depends on the kind of addition or modification you want to make. In our case, we want to add formatting information, which depends on the stream's character type since the format string is a sequence of tiny characters. As we show later on, the format string must be expanded into a sequence of the stream's character type for use with the stream's locale. Consequently, a good choice for a base class is class basic_iostream <charT,Traits>, and since we want the format string to impact only output operations, the best choice is class basic_ostream <charT,Traits>.
In general, you choose a base class by looking at the kind of addition or modification you want to make and comparing it with the characteristics of the stream classes.
Choose ios_base if you add information and services that do not depend on the stream's character type.
Choose basic_ios<charT, Traits> if the added information does depend on the character type, or requires other information not available in ios_base, such as the stream buffer.
Derive from the stream classes basic_istream <charT,Traits>, basic_ostream <charT,Traits>, or basic_iostream <charT, Traits> if you want to add or change the input and output operations.
Derive from the stream classes basic_(i/o)fstream <charT,Traits>, or basic_(i/o)stringstream <charT, Traits, Allocator> if you want to add or modify behavior that is file- or string-related, such as the way a file is opened.
Derivations from basic_istream <charT,Traits>, basic_ostream <charT,Traits>, or basic_iostream <charT, Traits> are the most common cases, because you typically want to modify or add input and output operations.
If you derive from ios_base or basic_ios<charT, Traits>, you do not inherit any input and output operations; you do this if you really want to reimplement all of them or intend to implement a completely different kind of input or output operation, such as unformatted binary input and output.
Derivations from file or string streams such as basic_(i/o)fstream <charT,Traits> or basic_(i/o)stringstream <charT, Traits, Allocator> are equally rare, because they make sense only if file- or string-related data or services must be added or modified.
NOTE: Choose basic_istream <charT,Traits>, basic_ostream <charT,Traits>, or basic_iostream <charT, Traits> as a base class when deriving new stream classes, unless you have good reason not to do so.
OEM Edition, ©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.