在线文档教程
C++
输入/输出 | Input/output

std::basic_istream::peek

性病:基本[医]iStream::peek

int_type peek(

表现为UnformattedInputFunction.在构造和测试哨兵对象之后,从输入流中读取下一个字符,而不提取它。

参数

%280%29

返回值

如果good() == true,返回由rdbuf()->sgetc()...

否则,返回Traits::eof()...

例外

failure如果发生错误%28,则错误状态标志不是goodbit29%和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

二次

另见

sgetcreads one character from the input sequence without advancing the sequence (public member function of std::basic_streambuf)
getextracts characters (public member function)
ungetunextracts a character (public member function)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/io/basic[医]iStream/PEEK