This documentation is archived and is not being maintained.


Read from buffer only.

streamsize _Readsome_s(
    char_type *_Str,
    size_t _Str_size,
    streamsize _Count


The array in which to read the characters.


The size of _Str.


The number of characters to read.

The count of items in the buffer.

The unformatted input function extracts up to count elements and stores them in the array beginning at _Str. If good is false, the function calls setstate(failbit). Otherwise, it assigns the value of rdbuf->in_avail to N. If N < 0, the function calls setstate(eofbit). Otherwise, it replaces the value stored in N with the smaller of _Count and N, and then calls read(_Str, N). In any case, the function returns gcount.

// basic_istream__Readsome_s.cpp
// compile with: /EHsc
#include <iostream>
using namespace std;

int main( )
    const int c_size = 10;
    char c[c_size];
    int count = 5;

    cout << "Type 'abcdefgh': ";

    // Can read from buffer or console
    cin._Read_s(&c[0], c_size, 2);

    // Can only read from buffer, not from console
    cin._Readsome_s(&c[0], c_size, count);
    c[count] = 0;
    cout << c << endl;


Type 'abcdefgh': abcdefgh

Header: <istream>

Namespace: std