std::basic_istream::putback
来自cppreference.com
< cpp | io | basic istream
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
basic_istream& putback( char_type ch ); |
||
看跌期权
ch
返回到输入流中的字符,以便在未来提取的字符将ch
. 原文:
Puts the character
ch
back to the input stream so the next extracted character will be ch
. 首先清除
eofbit
,然后表现为UnformattedInputFunction
。在构造和检查岗哨对象的,如果rdbuf()
不为空,调用rdbuf()->sputbackc(ch),这就要求rdbuf()->pbackfail(ch)ch
不等于最近一次提取的字符.原文:
First clears
eofbit
, then behaves as UnformattedInputFunction
. After constructing and checking the sentry object, if rdbuf()
is not null, calls rdbuf()->sputbackc(ch), which calls rdbuf()->pbackfail(ch) if ch
does not equal the most recently extracted character.如果
rdbuf()
是null,或者如果rdbuf->sputbackc(ch)回报Traits::eof(),来电setstate(badbit).原文:
If
rdbuf()
is null or if rdbuf->sputbackc(ch) returns Traits::eof(), calls setstate(badbit).在任何情况下,设置的计数器归零
gcount()
.原文:
In any case, sets the
gcount()
counter to zero.目录 |
[编辑] 参数
(无)
[编辑] 返回值
*this
[编辑] 示例
演示修改和非改性补篮()之间的差异
原文:
demonstrates the difference between modifying and non-modifying putback()
#include <sstream> #include <iostream> int main() { std::stringstream s1("Hello, world"); // IO stream s1.get(); if(s1.putback('Y')) // modifies the buffer std::cout << s1.rdbuf() << '\n'; else std::cout << "putback failed\n"; std::istringstream s2("Hello, world"); // input-only stream s2.get(); if(s2.putback('Y')) // cannot modify input-only buffer std::cout << s2.rdbuf() << '\n'; else std::cout << "putback failed\n"; s2.clear(); if(s2.putback('H')) // non-modifying putback std::cout << s2.rdbuf() << '\n'; else std::cout << "putback failed\n"; }
输出:
Yello, world putback failed Hello, world
[编辑] 另请参阅
unextracts一个字符 (公共成员函数) | |
读取下一个字符,而不提取 原文: reads the next character without extracting it (公共成员函数) |