std::basic_istream::peek
来自cppreference.com
< cpp | io | basic istream
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
int_type peek(); |
||
表现为
UnformattedInputFunction
。哨兵对象的构造和测试后,从输入流中读取下一个字符,而不必提取该. 原文:
Behaves as
UnformattedInputFunction
. After constructing and testing the sentry object, reads the next character from the input stream without extracting it. 目录 |
[编辑] 参数
(无)
[编辑] 返回值
如果good() == true,得到rdbuf()->sgetc()返回下一个字符
原文:
If good() == true, returns the next character as obtained by rdbuf()->sgetc()
否则,返回Traits::eof().
[编辑] 示例
#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
[编辑] 另请参阅
提取字符 (公共成员函数) | |
unextracts一个字符 (公共成员函数) |