C++
输入/输出 | Input/output

std::basic_streambuf::setg

性病:基本[医]Strebuf::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

二次

#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 }

二次

产出:

二次

This is an example

二次

另见

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

© cppreference.com

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

http://en.cppreference.com/w/cpp/io/basic[医]Streambuf/SETG