Namespaces
Variants
Views
Actions

std::basic_istream::unget

From cppreference.com
< cpp‎ | io‎ | basic istream
Revision as of 16:34, 8 December 2012 by Cubbi (Talk | contribs)

basic_istream& unget();

Makes the most recently extracted character available again.

First clears eofbit, then behaves as UnformattedInputFunction. After constructing and checking the sentry object, calls rdbuf()->sungetc().

If rdbuf()->sungetc() returns Traits::eof(), calls setstate(badbit).

In any case, sets the gcount() counter to zero.

Contents

Parameters

(none)

Return value

*this

Example

#include <sstream>
#include <iostream>
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';
    }
}

Output:

Got: H got again: H

See also

Template:cpp/io/basic streambuf/dcl list sungetcTemplate:cpp/io/basic istream/dcl list getTemplate:cpp/io/basic istream/dcl list peekTemplate:cpp/io/basic istream/dcl list putback