std::basic_istream::unget
From cppreference.com
< cpp | io | basic istream
basic_istream& unget(); |
||
Makes the most recently extracted character available again.
First clears eofbit, then constructs a std::basic_istream::sentry object with noskipws set to true. Afterwards, if good(), calls setstate(failbit) and returns. Otherwise, calls rdbuf()->sungetc().
If rdbuf()->sungetc() returns Traits::eof(), calls setstate(badbit).
In any case, sets the gcount() counter to zero.
Contents |
[edit] Parameters
(none)
[edit] Return value
*this
[edit] 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
[edit] See also
extracts characters (public member function) | |
reads the next character without extracting it (public member function) | |
puts character into input stream (public member function) |