std::strstreambuf::underflow
std::strflow buf::
protected: virtual int_type underflow( | | |
---|
从缓冲区的GET区域读取下一个字符。
如果输入序列有可用的读取位置,则%28gptr() < egptr()、回报(unsigned char)(*gptr())...
否则,如果pptr()不为空,并且pptr() > egptr()%28有一个PUT区域,它位于GET区域%29之后,扩展了GET区域的末尾,包括最近通过增量写入PUT区域的字符。egptr()到一定值之间gptr()和pptr(),然后返回(unsigned char)(*gptr())...
否则,返回EOF
表示失败。
参数
%280%29
返回值
下一个角色在GET区域,(unsigned char)(*gptr())
在成功的时候,EOF
在失败的时候。
例
二次
#include <strstream>
#include <iostream>
struct mybuf : std::strstreambuf
{
int_type overflow(int_type c)
{
std::cout << "Before overflow(): size of the get area is " << egptr()-eback()
<< " size of the put area is " << epptr()-pbase() << '\n';
int_type rc = std::strstreambuf::overflow(c
std::cout << "After overflow(): size of the get area is " << egptr()-eback()
<< " size of the put area is " << epptr()-pbase() << '\n';
return rc;
}
int_type underflow()
{
std::cout << "Before underflow(): size of the get area is " << egptr()-eback()
<< " size of the put area is " << epptr()-pbase() << '\n';
int_type ch = std::strstreambuf::underflow(
std::cout << "After underflow(): size of the get area is " << egptr()-eback()
<< " size of the put area is " << epptr()-pbase() << '\n';
if (ch == EOF) {
std::cout << "underflow() returns EOF\n";
} else {
std::cout << "underflow() returns '" << char(ch) << "'\n";
}
return ch;
}
};
int main()
{
mybuf sbuf; // read-write dynamic strstreambuf
std::iostream stream(&sbuf
int n;
stream >> n;
stream.clear(
stream << "123";
stream >> n;
std::cout << n << '\n';
}
二次
可能的产出:
二次
Before underflow(): size of the get area is 0 size of the put area is 0
After underflow(): size of the get area is 0 size of the put area is 0
underflow() returns EOF
Before overflow(): size of the get area is 0 size of the put area is 0
After overflow(): size of the get area is 0 size of the put area is 32
Before underflow(): size of the get area is 0 size of the put area is 32
After underflow(): size of the get area is 3 size of the put area is 32
underflow() returns '1'
Before underflow(): size of the get area is 3 size of the put area is 32
After underflow(): size of the get area is 3 size of the put area is 32
underflow() returns EOF
123
二次
另见
underflow virtual | reads characters from the associated input sequence to the get area (virtual protected member function of std::basic_streambuf) |
---|---|
underflow virtual | returns the next character available in the input sequence (virtual protected member function of std::basic_stringbuf) |
underflow virtual | reads from the associated file (virtual protected member function of std::basic_filebuf) |
sgetc | reads one character from the input sequence without advancing the sequence (public member function of std::basic_streambuf) |
get | extracts characters (public member function of std::basic_istream) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。