X
xmllmx
Dear all,
It is not easy to state in simple words. So please allow me to
introduce my own thoughts about it.
To my understanding, at least there are three characteristics which
make a stream different from a buffer:
#1, a stream can only hold human-readable characters(ansi/unicode),
while a buffer can hold any bytes such as 0.
#2, a stream can automatically maintain a current position after read/
write, while a buffer can't.
#3, a stream can smartly convert any object to human-readable
characters or vice versa, while a buffer can't.
For convenience, I will use "stream" to indicate the class istream/
ostream hereunder.
According to Object-Oriented principles, one class should not care
things which are not related to its responsibilities.
The class stream is responsible for convert any object to human-
readable characters or vice versa, so it is natural that the class
stream should care the locale. So the class basic_ios has imbue(), it
is easy to understand.
The class stream_buf is just responsible for reading/writing
characters, which are unrelated to the locale. The stream_buf doesn't
care what the characters represent. So stream_buf should not has the
member functions imbue() and pubimbue(). However, in fact, the C++
standard requires stream_buf must provide the two functions. WHY?
It is not easy to state in simple words. So please allow me to
introduce my own thoughts about it.
To my understanding, at least there are three characteristics which
make a stream different from a buffer:
#1, a stream can only hold human-readable characters(ansi/unicode),
while a buffer can hold any bytes such as 0.
#2, a stream can automatically maintain a current position after read/
write, while a buffer can't.
#3, a stream can smartly convert any object to human-readable
characters or vice versa, while a buffer can't.
For convenience, I will use "stream" to indicate the class istream/
ostream hereunder.
According to Object-Oriented principles, one class should not care
things which are not related to its responsibilities.
The class stream is responsible for convert any object to human-
readable characters or vice versa, so it is natural that the class
stream should care the locale. So the class basic_ios has imbue(), it
is easy to understand.
The class stream_buf is just responsible for reading/writing
characters, which are unrelated to the locale. The stream_buf doesn't
care what the characters represent. So stream_buf should not has the
member functions imbue() and pubimbue(). However, in fact, the C++
standard requires stream_buf must provide the two functions. WHY?