首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::basic_streambuf::setg

void setg( char_type* gbeg, char_type* gcurr, char_type* gend );

?

?

设置定义GET区域的指针的值。特别是在电话之后eback() == gbeg,,,gptr() == gcurr,,,egptr() == gend...

参数

gbeg

-

pointer to the new beginning of the get area

gcurr

-

pointer to the new current character (get pointer) in the get area

gend

-

pointer to the new end of the get area

返回值

%280%29

二次

代码语言:javascript
复制
#include <iostream>
#include <sstream>
 
class null_filter_buf : public std::streambuf {
    std::streambuf* src;
    char ch; // single-byte buffer
protected:
    int underflow() {
        while( (ch= src->sbumpc()) == '\0') ; // skip zeroes
        setg(&ch, &ch, &ch+1); // make one read position available
        return ch; // may return EOF
    }
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);
}

二次

产出:

二次

代码语言:javascript
复制
This is an example

二次

另见

setp

repositions the beginning, next, and end pointers of the output sequence (protected member function)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com