Namespaces
Variants

std::basic_streambuf<CharT,Traits>:: setg

From cppreference.net
protected :
void setg ( char_type * gbeg, char_type * gcurr, char_type * gend ) ;

가져오기 영역을 정의하는 포인터들의 값을 설정합니다.

호출 후에, eback ( ) == gbeg , gptr ( ) == gcurr 그리고 egptr ( ) == gend 가 모두 true 입니다.

다음 중 어느 하나라도 [ gbeg , gend ) , [ gbeg , gcurr ) 그리고 [ gcurr , gend ) 유효한 범위 가 아닌 경우, 동작은 정의되지 않습니다.

목차

매개변수

gbeg - get 영역의 새로운 시작을 가리키는 포인터
gcurr - get 영역 내 새로운 현재 문자( get pointer )를 가리키는 포인터
gend - get 영역의 새로운 끝을 가리키는 포인터

예제

#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

결함 보고서

다음 동작 변경 결함 보고서는 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 4023 C++98 setg 가 입력 시퀀스가 유효한 범위일 것을 요구하지 않았음 요구함

참고 항목

출력 시퀀스의 시작, 다음, 끝 포인터 위치를 재설정합니다
(protected member function)