basic_istream::readsome

지정 된 수의 문자 값을 읽습니다.

호출자가에 전달 된 값이 올바른지 확인 하므로이 메서드는 잠재적으로 안전 하지 않습니다.

streamsize readsome(
    char_type *str,
    streamsize count
);

매개 변수

  • str
    배열에는 readsome 가 읽은 문자를 저장 합니다.

  • count
    읽을 문자 수입니다.

반환 값

실제로 읽은 문자 수를 gcount.

설명

최대 입력된이 서식이 지정 되지 않은 함수 추출 count 요소는 입력에서 스트림 하 여 배열에 저장 str.

이 함수에 대 한 입력을 기다리지 않습니다.어떤 데이터를 사용할 수를 읽습니다.

예제

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

요구 사항

헤더: <istream>

네임 스페이스: std

참고 항목

참조

basic_istream Class

iostream 프로그래밍

iostreams 규칙