The effect of `basic_streambuf::setbuf`

后端 未结 2 1550
名媛妹妹
名媛妹妹 2020-12-17 14:46

My problem is as follows: Martin York claims in this, this, and this answers that one can make a stringstream read from some piece of memory by using basi

2条回答
  •  太阳男子
    2020-12-17 15:17

    I believe it is implementation defined and that you provided the relevant quotes.

    For the record, this is what Standard C++ IOStreams and locales, not exactly a recent book I have to admit, has to say on the subject in a section titled "The almost semantic free function - setbuf()" :

    The virtual member function setbuf() is a rather peculiar stream buffer member. Its semantics are basically undefined. For string stream buffers, the semantics of setbuf() are implementation-defined, except that setbuf(0, 0) are defined: if setbuf(0, 0) is called on a stream before and I/O has occured on that stream, the stream becomes unbuffered, meaning that characters are directly transported to and from the file system. Otherwise, the results are implementation-defined.

    However, the specifications of setbuf() for basic_filebuf and basic_stringbuf hardly impose any requirements on the semantics of setbuf() in other stream buffer types. At best, the general semantics can be defined as device and, in the case of user-defined stream buffer types, implementation-specific.

    The lack of any requirements frees you to redefine setbuf() for just about any purpose and in any way that fits into the predefined interface of setbuf().

提交回复
热议问题