std::basic_streambuf::setg
来自cppreference.com
< cpp | io | basic streambuf
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
void setg( char_type* gbeg, char_type* gcurr, char_type* gend ); |
||
设置限定的get区域的指针值。具体而言,在调用后eback() == gbeg,gptr() == gcurr,egptr() == gend
原文:
Sets the values of the pointers defining the get area. Specifically, after the call eback() == gbeg, gptr() == gcurr, egptr() == gend
目录 |
[编辑] 参数
gbeg | - | 指针的get地区的新的开始
原文: pointer to the new beginning of the get area |
gcurr | - | 新的当前字符(“指针”)在get区的指针
原文: pointer to the new current character (get pointer) in the get area |
gend | - | 向新的get区的指针
原文: pointer to the new end of the get area |
[编辑] 返回值
(无)
[编辑] 示例
#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
[编辑] 另请参阅
重新定位的开始,接着,和结束指针的输出序列 原文: repositions the beginning, next, and end pointers of the output sequence (受保护的成员函数) |