Namespaces
Variants

std::strstreambuf:: underflow

From cppreference.net
protected :
virtual int_type underflow ( ) ;
(C++98에서 사용 중단됨)
(C++26에서 제거됨)

버퍼의 get 영역에서 다음 문자를 읽습니다.

입력 시퀀스에 읽기 위치가 사용 가능한 경우( gptr ( ) < egptr ( ) ), ( unsigned char ) ( * gptr ( ) ) 를 반환합니다.

그렇지 않고, pptr() 가 null이 아니고 pptr ( ) > egptr ( ) (put 영역이 존재하고 get 영역 뒤에 위치하는 경우)인 경우, get 영역의 끝을 put 영역에 최근 기록된 문자들을 포함하도록 확장합니다. 이를 위해 egptr() gptr ( ) pptr() 사이의 어떤 값으로 증가시킨 후, ( unsigned char ) ( * gptr ( ) ) 를 반환합니다.

그렇지 않으면, 실패를 나타내기 위해 EOF 를 반환합니다.

목차

매개변수

(없음)

반환값

get 영역의 다음 문자, ( unsigned char ) ( * gptr ( ) ) 성공 시, EOF 실패 시.

예제

#include <iostream>
#include <strstream>
struct mybuf : std::strstreambuf
{
    int_type overflow(int_type c) 
    {
        std::cout << "Before overflow(): size of the get area is " << egptr()-eback()
                  << " size of the put area is " << epptr()-pbase() << '\n';
        int_type rc = std::strstreambuf::overflow(c);
        std::cout << "After overflow(): size of the get area is " << egptr()-eback()
                  << " size of the put area is " << epptr()-pbase() << '\n';
        return rc;
    }
    int_type underflow() 
    {
        std::cout << "Before underflow(): size of the get area is " << egptr()-eback()
                  << " size of the put area is " << epptr()-pbase() << '\n';
        int_type ch = std::strstreambuf::underflow();
        std::cout << "After underflow(): size of the get area is " << egptr()-eback()
                  << " size of the put area is " << epptr()-pbase() << '\n';
        if (ch == EOF)
            std::cout << "underflow() returns EOF\n";
        else
            std::cout << "underflow() returns '" << char(ch) << "'\n";
        return ch;
    }
};
int main()
{
    mybuf sbuf; // read-write dynamic strstreambuf
    std::iostream stream(&sbuf);
    int n;
    stream >> n;
    stream.clear();
    stream << "123";
    stream >> n;
    std::cout << n << '\n';
}

가능한 출력:

Before underflow(): size of the get area is 0 size of the put area is 0
After underflow(): size of the get area is 0 size of the put area is 0
underflow() returns EOF
Before overflow(): size of the get area is 0 size of the put area is 0
After overflow(): size of the get area is 0 size of the put area is 32
Before underflow(): size of the get area is 0 size of the put area is 32
After underflow(): size of the get area is 3 size of the put area is 32
underflow() returns '1'
Before underflow(): size of the get area is 3 size of the put area is 32
After underflow(): size of the get area is 3 size of the put area is 32
underflow() returns EOF
123

참고 항목

[virtual]
연관된 입력 시퀀스에서 문자를 읽어 get 영역으로 가져옴
( std::basic_streambuf<CharT,Traits> 의 virtual protected 멤버 함수)
[virtual]
입력 시퀀스에서 사용 가능한 다음 문자를 반환함
( std::basic_stringbuf<CharT,Traits,Allocator> 의 virtual protected 멤버 함수)
[virtual]
연관된 파일에서 읽기
( std::basic_filebuf<CharT,Traits> 의 virtual protected 멤버 함수)
시퀀스를 진행시키지 않고 입력 시퀀스에서 한 문자를 읽음
( std::basic_streambuf<CharT,Traits> 의 public 멤버 함수)
문자를 추출함
( std::basic_istream<CharT,Traits> 의 public 멤버 함수)