std::basic_streambuf<CharT,Traits>:: underflow
|
protected
:
virtual int_type underflow ( ) ; |
||
입력 영역에 최소한 하나의 문자가 사용 가능하도록 보장합니다(필요한 경우 입력 영역에 대한 포인터를 업데이트하고, 적용 가능한 경우 입력 시퀀스에서 더 많은 데이터를 읽어옵니다). 성공 시 해당 문자 값을(
int_type
으로 변환된
Traits
::
to_int_type
(
c
)
) 반환하거나 실패 시
Traits
::
eof
(
)
를 반환합니다.
이 함수는 새로 로드된 데이터의 위치(있는 경우)를 정의하기 위해
gptr
,
egptr
및
eback
포인터를 업데이트할 수 있습니다. 실패 시, 이 함수는
gptr
(
)
==
nullptr
또는
gptr
(
)
==
egptr
가 되도록 보장합니다.
기본 클래스 버전의 함수는 아무 작업도 수행하지 않습니다. 파생 클래스들은 소진 시 get 영역 업데이트를 허용하기 위해 이 함수를 재정의할 수 있습니다.
목차 |
매개변수
(없음)
반환값
호출이 성공한 후 get pointer 가 가리키는 문자의 값, 그렇지 않으면 Traits :: eof ( ) 입니다.
이 함수의 기본 클래스 버전은 traits :: eof ( ) 를 반환합니다.
참고
std::streambuf 의 공개 함수들은 다음 조건에서만 이 함수를 호출합니다: gptr ( ) == nullptr 또는 gptr ( ) >= egptr ( ) .
예제
#include <iostream> #include <sstream> class null_filter_buf : public std::streambuf { std::streambuf* src; char ch; // single-byte buffer protected: int underflow() { traits_type::int_type i; while ((i = src->sbumpc()) == '\0') ; // skip zeroes if (!traits_type::eq_int_type(i, traits_type::eof())) { ch = traits_type::to_char_type(i); setg(&ch, &ch, &ch+1); // make one read position available } return i; } public: null_filter_buf(std::streambuf* buf) : src(buf) { setg(&ch, &ch + 1, &ch + 1); // buffer is initially full } }; void filtered_read(std::istream& in) { std::streambuf* orig = in.rdbuf(); null_filter_buf buf(orig); in.rdbuf(&buf); for (char c; in.get(c);) std::cout << c; in.rdbuf(orig); } int main() { char a[] = "This i\0s \0an e\0\0\0xample"; std::istringstream in(std::string(std::begin(a), std::end(a))); filtered_read(in); }
출력:
This is an example
참고 항목
|
[virtual]
|
연관된 입력 시퀀스에서 문자를 읽어 get 영역으로 가져오고 다음 포인터를 전진시킴
(가상 protected 멤버 함수) |
|
[virtual]
|
put 영역에서 연관된 출력 시퀀스로 문자를 기록함
(가상 protected 멤버 함수) |
|
[virtual]
|
연관된 파일에서 읽어옴
(
std::basic_filebuf<CharT,Traits>
의 가상 protected 멤버 함수)
|
|
[virtual]
|
입력 시퀀스에서 사용 가능한 다음 문자를 반환함
(
std::basic_stringbuf<CharT,Traits,Allocator>
의 가상 protected 멤버 함수)
|
|
[virtual]
|
다음 포인터를 전진시키지 않고 입력 시퀀스에서 문자를 읽어옴
(
std::strstreambuf
의 가상 protected 멤버 함수)
|