Namespaces
Variants

std::basic_istream<CharT,Traits>:: readsome

From cppreference.net
std:: streamsize readsome ( char_type * s, std:: streamsize count ) ;

입력 스트림에서 즉시 사용 가능한 최대 count 개의 문자를 추출합니다. 추출된 문자들은 s 가 가리키는 문자 배열에 저장됩니다.

UnformattedInputFunction 로 동작합니다. 센트리 객체를 구성하고 검사한 후,

  • 만약 rdbuf ( ) - > in_avail ( ) == - 1 인 경우, setstate ( eofbit ) 를 호출하고 어떤 문자도 추출하지 않습니다.
  • 만약 rdbuf ( ) - > in_avail ( ) == 0 이면, 어떤 문자도 추출하지 않습니다.
  • 만약 rdbuf ( ) - > in_avail ( ) > 0 이면, std:: min ( rdbuf ( ) - > in_avail ( ) , count ) 개의 문자를 추출하여 s 가 가리키는 첫 번째 요소부터 시작하는 문자 배열의 연속된 위치에 저장합니다.

목차

매개변수

s - 문자를 저장할 문자 배열에 대한 포인터
count - 읽을 최대 문자 수

반환값

실제로 추출된 문자 수.

예외

failure if an error occurred (the error state flag is not goodbit ) and exceptions() is set to throw for that state.

내부 연산에서 예외가 발생하면, 해당 예외는 포착되고 badbit 이 설정됩니다. 만약 exceptions() badbit 에 대해 설정되어 있다면, 예외가 다시 발생됩니다.

참고 사항

이 함수의 동작은 구현에 따라 크게 달라집니다. 예를 들어, readsome() std::ifstream 과 함께 사용하면 구현에 따라 상이한 중요한 결과가 발생합니다. 일부 라이브러리 구현에서는 std::ifstream 이 파일을 열자마자 기본 filebuf 를 데이터로 채우기 때문에 readsome() 이 항상 데이터를 읽어들이고 전체 파일을 읽을 수도 있습니다. 다른 구현에서는 std::ifstream 이 입력 연산이 호출될 때만 파일에서 읽기를 수행하므로, 파일을 연 직후 readsome() 을 호출하면 어떤 문자도 추출되지 않습니다. 마찬가지로 std:: cin . readsome ( ) 을 호출하면 대기 중인 모든 미처리 콘솔 입력을 반환할 수도 있고, 항상 0을 반환하며 어떤 문자도 추출하지 않을 수도 있습니다.

예제

#include <cassert>
#include <iostream>
#include <sstream>
int main()
{
    char c[10] = "*********"; // c[9] == '\0'
    // std::stringbuf makes its entire buffer available for unblocking read
    std::istringstream input("This is sample text.");
    auto r = input.readsome(c, 5); // reads 'This ' and stores in c[0] .. c[4]
    assert(r == 5);
    std::cout << c << '\n';
    r = input.readsome(c, 9); // reads 'is sample' and stores in c[0] .. c[8]
    assert(r == 9);
    std::cout << c << '\n';
}

출력:

This ****
is sample

참고 항목

문자 블록을 추출합니다
(public member function)
get area에서 즉시 사용 가능한 문자 수를 얻습니다
( std::basic_streambuf<CharT,Traits> 의 public member function)