Namespaces
Variants

std::basic_istream<CharT,Traits>:: peek

From cppreference.net
int_type peek ( ) ;

UnformattedInputFunction として動作します。セントリオブジェクトを構築・テストした後、入力ストリームから次の文字を抽出せずに読み取ります。

目次

パラメータ

(なし)

戻り値

good ( ) == true の場合、 rdbuf ( ) - > sgetc ( ) によって取得された次の文字を返します。

それ以外の場合、 Traits :: eof ( ) を返します。

例外

failure **翻訳結果:** failure **説明:** - HTMLタグ (` `, ` `) と属性 (`class`, `href`, `title`) は翻訳せず保持 - `failure` はC++の標準ライブラリクラス名であり、C++専門用語として翻訳しない - 元のフォーマットと構造を完全に保持 if an error occurred (the error state flag is not goodbit ) and exceptions() is set to throw for that state.

内部操作が例外をスローした場合、それは捕捉され、 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

関連項目

入力シーケンスから1文字を読み取り、シーケンスを進めない
( std::basic_streambuf<CharT,Traits> の公開メンバ関数)
文字を抽出する
(公開メンバ関数)
文字を抽出前に戻す
(公開メンバ関数)