I/O manipulators | ||||
Print functions(C++23) | ||||
C-style I/O | ||||
Buffers | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++20) | ||||
Streams | ||||
Abstractions | ||||
File I/O | ||||
String I/O | ||||
Array I/O | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
Synchronized Output | ||||
(C++20) | ||||
Types | ||||
Error category interface | ||||
(C++11) | ||||
(C++11) |
Global objects | ||||
Member functions | ||||
(C++11) | ||||
Formatted input | ||||
Unformatted input | ||||
basic_istream::readsome | ||||
Positioning | ||||
Miscellaneous | ||||
(C++11) | ||||
Member classes | ||||
Non-member functions | ||||
std::streamsize readsome( char_type* s,std::streamsize count); | ||
Extracts up tocount immediately available characters from the input stream. The extracted characters are stored into the character array pointed to bys.
Behaves asUnformattedInputFunction. After constructing and checking the sentry object,
Contents |
s | - | pointer to the character array to store the characters to |
count | - | maximum number of characters to read |
The number of characters actually extracted.
If an internal operation throws an exception, it is caught andbadbit is set. Ifexceptions() is set forbadbit
, the exception is rethrown.
The behavior of this function is highly implementation-specific. For example, usingreadsome()
withstd::ifstream leads to significant, implementation-specific outcomes. Some library implementations fill the underlyingfilebuf
with data as soon asstd::ifstream opens a file, which meansreadsome()
always reads data and could even read the entire file. With other implementations,std::ifstream only reads from a file when an input operation is invoked, which means callingreadsome()
immediately after opening the file never extracts any characters. Similarly, callingstd::cin.readsome() may return all pending, unprocessed console input or may always return zero and extract no characters.
#include <cassert>#include <iostream>#include <sstream> int main(){char c[10]="*********";// c[9] == '\0' // std::stringbuf makes its entire buffer available for unblocking readstd::istringstream input("This is sample text."); auto r= input.readsome(c,5);// reads 'This ' and stores in c[0] .. c[4]assert(r==5);std::cout<< c<<'\n'; r= input.readsome(c,9);// reads 'is sample' and stores in c[0] .. c[8]assert(r==9);std::cout<< c<<'\n';}
Output:
This ****is sample
extracts blocks of characters (public member function)[edit] | |
obtains the number of characters immediately available in the get area (public member function of std::basic_streambuf<CharT,Traits> )[edit] |