public member function
std::istream::readsome
<istream>
streamsize readsome ( char* s, streamsize n );
Read block of data available in the buffer
Reads a block of data of up to
n characters and stores it in the array pointed by
s, but unlike member function
read,
readsome stops reading if the memory buffer associated with the stream runs out of characters, even if the End-Of-File has not yet been reached.
The function is intended to be used to read binary data from certain types of asynchronic sources that may wait for more characters, since it stops reading when the local buffer exhausts, avoiding potential unexpected delays.
Parameters
- s
- Pointer to an array of characters where the content read will be stored.
- n
- Integer value of type streamsize representing the size of the block of data to be read.
Return Value
The number of characters extracted.
Errors are signaled by modifying the internal state flags:
| flag | error |
| eofbit | The get pointer is at the end of the stream buffer's internal input array when the function is called, meaning that there are no positions to be read in the internal buffer (which may or not be the end of the input sequence). This happens when rdbuf()->in_avail() would return -1 before the first character is extracted. |
| failbit | The stream was at the end of the source of characters before the function was called. |
| badbit | An error other than the above happened. |
Additionally, in any of these cases, if the appropriate flag has been set with member function
ios::exceptions, an exception of type
ios_base::failure is thrown.
Basic template member declaration
( basic_istream<charT,traits> )
1 2
|
typedef charT char_type;
streamsize readsome ( char_type* s, streamsize n );
|
See also
- istream::read
- Read block of data (public member function)
- ostream::write
- Write block of data (public member function)
- istream::operator>>
- Extract formatted data (public member function)