std::basic_istream<CharT,Traits>::peek
來自 cppreference.com
< cpp | io | basic istream
int_type peek(); |
||
其行為類似於非格式化輸入函式 (UnformattedInputFunction)。在構造並測試哨兵物件後,從輸入流中讀取下一個字元,但不將其提取。
目錄 |
[編輯] 引數
(無)
[編輯] 返回值
如果 good() == true,則返回透過 rdbuf()->sgetc() 獲取的下一個字元。
否則,返回 Traits::eof()。
[編輯] 異常
如果內部操作丟擲異常,則會被捕獲並設定 badbit。如果 exceptions() 為 `badbit` 設定,則會重新丟擲異常。
[編輯] 示例
執行此程式碼
#include <iostream> #include <sstream> 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
[編輯] 參閱
從輸入序列中讀取一個字元而不推進序列 ( std::basic_streambuf<CharT,Traits> 的公開成員函式) | |
提取字元 (公開成員函式) | |
取消提取字元 (公開成員函式) |