std::basic_istream<CharT,Traits>::unget
From cppreference.com
basic_istream& unget(); |
||
Makes the most recently extracted character available again.
If eofbit flag is set before the call, the function fails (sets |
(until C++11) |
First clears eofbit. |
(since C++11) |
Then the function behaves as Template:concept. 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
Exceptions
If an internal operation throws an exception, it is caught and badbit is set. If exceptions() is set for badbit
, the exception is rethrown.
Example
Run this code
#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
moves the next pointer in the input sequence back by one (public member function of std::basic_streambuf<CharT,Traits> )
| |
extracts characters (public member function) | |
reads the next character without extracting it (public member function) | |
puts a character into input stream (public member function) |