std::basic_istream::peek
性病:基本[医]iStream::peek
int_type peek( | | |
---|
表现为UnformattedInputFunction
.在构造和测试哨兵对象之后,从输入流中读取下一个字符,而不提取它。
参数
%280%29
返回值
如果good() == true,返回由rdbuf()->sgetc()...
否则,返回Traits::eof()
...
例外
failure
如果发生错误%28,则错误状态标志不是goodbit
29%和exceptions()
将被抛向那个州。
如果内部操作抛出异常,则会捕获该操作,并且badbit
已经设定好了。如果exceptions()
设置为badbit
,异常将被重新抛出。
例
二次
#include <sstream>
#include <iostream>
int main()
{
std::istringstream s1("Hello, world."
char c1 = s1.peek(
char c2 = s1.get(
std::cout << "Peeked: " << c1 << " got: " << c2 << '\n';
}
二次
产出:
二次
Peeked: H got: H
二次
另见
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) |
unget | unextracts a character (public member function) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。