In the stream library the use of arrays of characters as sources or sinks was supported as the default behavior of streambuf. Although some attempt to preserve the default behavior is made by the iostream library these uses of a streambuf are considered obsolete. The support of incore operations is specifically the responsibility of the strstreambuf declared in strstream.h. streambufs created for this purpose can usually be replaced directly by strstreambufs that have equivalent behavior. The stream usage:
char* buf ; streambuf b(buf,10) ;is equivalent to the iostream:
char* buf ; strstreambuf b(buf,10) ;and the old method for initializing a streambuf for extraction:
char* buf ; streambuf b ; b.setbuf(buf,10,buf+5) ;is equivalent to the iostream method:
char* buf ; strstreambuf b(buf,10,buf+5) ;
Frequently these uses of streambuf do not appear explicitly in the program but are the consequence of using certain constructors of istream and ostream. These constructors are supplied in the iostream library, but are considered obsolete. The equivalent forms using strstream should be used.
The old method of storing a formatted value into an array:
char* buf ; ostream out(10,b) ;is replaced by:
char* buf ; ostrstream out(b,10) ;Note that the order of the arguments is reversed. The new order creates more consistency between various uses of strstreams.
The old method of extracting a formatted value from an array:
char* buf ; istream in(10,b) ;is replaced by
char* buf ; istrstream in(b,10) ;
The old istream() constructor allowed an optional extra argument to specify skipping of whitespace. In the iostream library this is part of a greatly expanded collection of state variables and so an extra argument is not provided for the istrstream() constructor. However, the obsolete form of istream() constructor continues to accept these optional arguments.