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
);
매개 변수
str
The array in which readsome stores the characters it reads.count
읽을 문자 수입니다.
반환 값
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 wait for input. It 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>
네임스페이스: std