Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

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

      From cppreference.com
      <cpp‎ |io‎ |basic istream
       
       
       
       
      int_type peek();

      Behaves asUnformattedInputFunction. After constructing and testing the sentry object, reads the next character from the input stream without extracting it.

      Contents

      [edit]Parameters

      (none)

      [edit]Return value

      Ifgood()==true, returns the next character as obtained byrdbuf()->sgetc().

      Otherwise, returnsTraits::eof().

      [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.peek();char c2= s1.get();std::cout<<"Peeked: "<< c1<<" got: "<< c2<<'\n';}

      Output:

      Peeked: H got: H

      [edit]See also

      reads one character from the input sequence without advancing the sequence
      (public member function ofstd::basic_streambuf<CharT,Traits>)[edit]
      extracts characters
      (public member function)[edit]
      unextracts a character
      (public member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/basic_istream/peek&oldid=158520"

      [8]ページ先頭

      ©2009-2025 Movatter.jp