protected virtual member function
<streambuf> <iostream>


streamsize xsgetn (char_type* s, streamsize n);
Get sequence of characters
Retrieves characters from the controlled input sequence and stores them in the array pointed by s, until either n characters have been extracted or the end of the sequence is reached.

Its default behavior in basic_streambuf is equivalent to calling sbumpc n times, stopping if any call would return traits_type::eof().

This is a virtual member function, and derived classes may provide a more efficient implementation. In fact, most library implementations override it for basic_filebuf and/or basic_stringbuf.


Pointer to an array where the character sequence is copied.
Member type char_type is the type of the characters in the stream buffer (the first class template parameter).
Maximum number of characters to be retrieved.
This shall be a non-negative value.
streamsize is a signed integral type.

Return Value

The number of characters copied.
streamsize is a signed integral type.

Data races

Modifies up to all of the first n characters in the array pointed by s.
Modifies the stream buffer object.
Concurrent access to the same array or to the same stream buffer object may introduce data races.

Exception safety

Basic guarantee: if an exception is thrown, the stream buffer is in a valid state (this also applies to standard derived classes).

Invalid arguments cause undefined behavior.

See also