| I/O manipulators | ||||
| Print functions(C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++20) | ||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
| Synchronized Output | ||||
(C++20) | ||||
| Types | ||||
| Error category interface | ||||
(C++11) | ||||
(C++11) |
| Global objects | ||||
| Member functions | ||||
(C++11) | ||||
| Formatted input | ||||
| Unformatted input | ||||
basic_istream::unget | ||||
| Positioning | ||||
| Miscellaneous | ||||
(C++11) | ||||
| Member classes | ||||
| Non-member functions | ||||
basic_istream& unget(); | ||
Makes the most recently extracted character available again.
First, clearseofbit. Then,(since C++11)unget behaves asUnformattedInputFunction. After constructing and checking the sentry object, if anyios_base::iostate flags are set, the function setsfailbit and returns. Otherwise, callsrdbuf()->sungetc().
Ifrdbuf()->sungetc() returnsTraits::eof(), callssetstate(badbit).
In any case, sets thegcount() counter to zero.
Contents |
(none)
*this
If an internal operation throws an exception, it is caught andbadbit is set. Ifexceptions() is set forbadbit, the exception is rethrown.
#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";}}
Output:
Got: 'H'. Got again: 'H'.
| moves the next pointer in the input sequence back by one (public member function of std::basic_streambuf<CharT,Traits>)[edit] | |
| extracts characters (public member function)[edit] | |
| reads the next character without extracting it (public member function)[edit] | |
| puts a character into input stream (public member function)[edit] |