c++iostreamlanguage-history

Why were the iostream_withassign, ostream_withassign & istream_withassign classes removed from the C++ I/O system?


Prior to C++98, in the C++ I/O class hierarchy there were 3 classes named iostream_withassign, ostream_withassign & istream_withassign.

Member functions of iostream_withassign class:

Constructors & Destructor

~iostream_withassign

public:virtual ~iostream_withassign()

iostream_withassign

public:iostream_withassign()

Creates an iostream_withassign object. It does not do any initialization of this object.

operator =

public:iostream_withassign& operator =(iostream_withassign& rhs)

Assignment Operators operator =

Overload 1

public:iostream_withassign& operator =(streambuf*)

This assignment operator takes a pointer to a streambuf object and associates this streambuf object with the iostream_withassign object that is on the left side of the assignment operator.

Overload 2

public:iostream_withassign& operator =(ios&)

This assignment operator takes an lvalue reference to an ios object and associates the stream buffer attached to this ios object with the iostream_withassign object that is on the left side of the assignment operator.

Source: this.

Same way this says that:

The ostream_withassign class is a variant of ostream that allows object assignment. The predefined objects cout, cerr, and clog are objects of this class and thus may be reassigned at run time to a different ostream object. For example, a program that normally sends output to stdout could be temporarily directed to send its output to a disk file. It also contains constructor, destructor & =(assignment) operator functions.

I don't understand, why did these classes exist? Was there any use of these 3 classes? Why later on these 3 classes were removed from the C++98 standard? What is the reason?

See C++ stream class hierarchy also. It doesn't have these 3 classes.

C++ I/O class hierarchy


Solution

  • They where found to be deficient. They are replace by:

    1. iostate rdstate() to reads the stream state.
    2. void clear(iostate state = goodbit) to set the stream state.
    3. basic_streambuf<class charT, class Traits>* rdbuf() to retrieve the stream buffer.
    4. basic_streambuf<class charT, class Traits>* rdbuf(basic_streambuf<class charT, class Traits>* sb) to set the stream buffer.
    5. basic_ios<class charT, class Traits>& copyfmt(basic_ios<class charT, class Traits>& rhs) to set all other data members of rhs.