Export (0) Print
Expand All

basic_istream::readsome 

Read from buffer only.

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
);

Parameters

_Str

The array in which to read the characters.

_Count

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.cpp
// compile with: /EHsc /W3
#include <iostream>
using namespace std;

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

   cout << "Type 'abcdefgh': ";

   // Can read from buffer or console
   // Note: cin::read is potentially unsafe, consider
   // using cin::_Read_s instead.
   cin.read(&c[0], 2);

   // Can only read from buffer, not from console
   // Note: cin::readsome is potentially unsafe, consider
   // using cin::_Readsome_s instead.
   cin.readsome(&c[0], count);  // C4996
   c[count] = 0;
   cout << c << endl;
}

abcdefgh

Type 'abcdefgh': abcdefgh
cdefg

Header: <istream>

Community Additions

ADD
Show:
© 2014 Microsoft