std::basic_istream::unget
性病:基本[医]iStream::unget
basic_istream& unget( | | |
---|
使最近提取的字符再次可用。
First clears eofbit. | (since C++11) |
---|
然后,该函数表现为UnformattedInputFunction.在构造和检查哨兵对象(如果有的话)之后ios_base::iostate设置标志,则设置函数集。failbit然后回来。否则,打电话rdbuf()->sungetc()...
如果rdbuf()->sungetc()回报Traits::eof(),电话setstate(badbit)...
在任何情况下,设置gcount()
对零。
参数
%280%29
返回值
*this
...
例外
failure
如果发生错误%28,则错误状态标志不是goodbit
29%和exceptions()
将被抛向那个州。
如果内部操作抛出异常,则会捕获该操作,并且badbit
已经设定好了。如果exceptions()
设置为badbit
,异常将被重新抛出。
例
二次
#include <sstream>
#include <iostream>
int main()
{
std::istringstream s1("Hello, world."
char c1 = s1.get(
if (s1.unget())
{
char c2 = s1.get(
std::cout << "Got: " << c1 << " got again: " << c2 << '\n';
}
}
二次
产出:
二次
Got: H got again: H
二次
另见
sungetc | moves the next pointer in the input sequence back by one (public member function of std::basic_streambuf) |
---|---|
get | extracts characters (public member function) |
peek | reads the next character without extracting it (public member function) |
putback | puts character into input stream (public member function) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。