Namespaces
Variants

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

From cppreference.net
basic_istream & unget ( ) ;

直前に抽出された文字を再度利用可能にします。

まず最初に eofbit をクリアします。その後、 (C++11以降) unget UnformattedInputFunction として動作します。セントリオブジェクトを構築してチェックした後、 ios_base::iostate フラグが設定されている場合、関数は failbit を設定して返ります。そうでない場合、 rdbuf ( ) - > sungetc ( ) を呼び出します。

rdbuf ( ) - > sungetc ( ) Traits :: eof ( ) を返す場合、 setstate ( badbit ) を呼び出す。

いずれの場合も、 gcount() カウンターをゼロに設定します。

目次

パラメータ

(なし)

戻り値

* this

例外

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.get();
    if (s1.unget())
    {
        char c2 = s1.get();
        std::cout << "Got: '" << c1 << "'. Got again: '" << c2 << "'.\n";
    }
}

出力:

Got: 'H'. Got again: 'H'.

関連項目

入力シーケンスの次のポインタを1つ戻す
( std::basic_streambuf<CharT,Traits> の公開メンバ関数)
文字を抽出する
(公開メンバ関数)
次の文字を抽出せずに読み取る
(公開メンバ関数)
入力ストリームに文字を戻す
(公開メンバ関数)