Freigeben über


basic_istream::readsome

Reads the specified number of character values.

This method is potentially unsafe, as it relies on the caller to check that the passed values are correct.

streamsize readsome(
    char_type *str,
    streamsize count
);

Parameters

  • str
    The array in which readsome stores the characters it reads.

  • count
    The number of characters to read.

Return Value

The number of characters actually read, gcount.

Remarks

This unformatted input function extracts up to count elements from the input stream and stores them in the array str.

This function does not wait for input. It reads whatever data is available.

Example

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

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

   cout << "Type 'abcdefgh': ";

   // cin.read blocks until user types input.
   // Note: cin::read is potentially unsafe, consider
   // using cin::_Read_s instead.
   cin.read(&c[0], 2);

   // Note: cin::readsome is potentially unsafe, consider
   // using cin::_Readsome_s instead.
   int n = cin.readsome(&c[0], count);  // C4996
   c[n] = 0;
   cout << n << " characters read" << endl;
   cout << c << endl;
}

Input

abcdefgh

Sample Output

Type 'abcdefgh': abcdefgh
5 characters read
cdefg

Requirements

Header: <istream>

Namespace: std

See Also

Reference

basic_istream Class

iostream Programming

iostreams Conventions