Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

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

      From cppreference.com
      <cpp‎ |io‎ |basic istream
       
       
       
       
      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

      [edit]Parameters

      (none)

      [edit]Return value

      *this

      [edit]Exceptions

      [edit]
      failure if an error occurred (the error state flag is notgoodbit) andexceptions() is set to throw for that state.

      If an internal operation throws an exception, it is caught andbadbit is set. Ifexceptions() is set forbadbit, the exception is rethrown.

      [edit]Example

      Run this code
      #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'.

      [edit]See also

      moves the next pointer in the input sequence back by one
      (public member function ofstd::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]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/basic_istream/unget&oldid=154435"

      [8]ページ先頭

      ©2009-2025 Movatter.jp