This documentation is archived and is not being maintained.

basic_istream::readsome

Updated: October 2008

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. Consider using basic_istream::_Readsome_s instead.

streamsize readsome(
    char_type *str,
    streamsize count
);

str

The array in which readsome stores the characters it reads.

count

The number of characters to read.

The number of characters actually read, gcount.

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

This function does not block. That is, it does not wait for input, it just reads whatever data is available.

// 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;
}

abcdefgh

Type 'abcdefgh': abcdefgh
5 characters read
cdefg

Header: <istream>

Namespace: std

Date

History

Reason

October 2008

Revised.

Customer feedback.

Show: