30 Input/output library [input.output]

30.6 Stream buffers [stream.buffers]

30.6.3 Class template basic_­streambuf [streambuf] basic_­streambuf virtual functions [streambuf.virtuals] Put area [streambuf.virt.put]

streamsize xsputn(const char_type* s, streamsize n);

Effects: Writes up to n characters to the output sequence as if by repeated calls to sputc(c). The characters written are obtained from successive elements of the array whose first element is designated by s. Writing stops when either n characters have been written or a call to sputc(c) would return traits​::​eof(). It is unspecified whether the function calls overflow() when pptr() == epptr() becomes true or whether it achieves the same effects by other means.

Returns: The number of characters written.

int_type overflow(int_type c = traits::eof());

Effects: Consumes some initial subsequence of the characters of the pending sequence. The pending sequence is defined as the concatenation of

  • the empty sequence if pbase() is not null, otherwise the pptr() - pbase() characters beginning at pbase(), followed by

  • the empty sequence if traits​::​eq_­int_­type(c, traits​::​eof()) returns true, otherwise the sequence consisting of c.

Remarks: The member functions sputc() and sputn() call this function in case that no room can be found in the put buffer enough to accommodate the argument character sequence.

Requires: Every overriding definition of this virtual function shall obey the following constraints:

  1. 1.The effect of consuming a character on the associated output sequence is specified303

  2. 2.Let r be the number of characters in the pending sequence not consumed. If r is nonzero then pbase() and pptr() shall be set so that: pptr() - pbase() == r and the r characters starting at pbase() are the associated output stream. In case r is zero (all characters of the pending sequence have been consumed) then either pbase() is set to nullptr, or pbase() and pptr() are both set to the same non-null value.

  3. 3.The function may fail if either appending some character to the associated output stream fails or if it is unable to establish pbase() and pptr() according to the above rules.

Returns: traits​::​eof() or throws an exception if the function fails.

Otherwise, returns some value other than traits​::​eof() to indicate success.304

Default behavior: Returns traits​::​eof().

That is, for each class derived from an instance of basic_­streambuf in this Clause ([stringbuf], [filebuf]), a specification of how consuming a character effects the associated output sequence is given. There is no requirement on a program-defined class.

Typically, overflow returns c to indicate success, except when traits​::​eq_­int_­type(c, traits​::​eof()) returns true, in which case it returns traits​::​not_­eof(c).