Compartir a través de


basic_istream::_Read_s

Reads a specified number of characters from the stream and stores them in an array.

basic_istream<Elem, Tr>& _Read_s(
    char_type *_Str,
    size_t _Str_size,
    streamsize _Count
);

Parameters

  • _Str
    The array in which to read the characters.

  • _Str_size
    The size of _Str.

  • _Count
    The number of characters to read.

Return Value

The stream (*this).

Remarks

The unformatted input function extracts up to count elements and stores them in the array beginning at _Str. Extraction stops early on end of file, in which case the function calls setstate(failbit). In any case, it returns *this.

Example

// basic_istream__Read_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 'abcde': ";

    cin._Read_s(&c[0], c_size, count);
    c[count] = 0;

    cout << c << endl;
}

abcde

Type 'abcde': abcde
abcde

Requirements

Header: <istream>

Namespace: std

See Also

Concepts

basic_istream Class

basic_istream Members

iostream Programming

iostreams Conventions

Safe Libraries: Standard C++ Library