Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::strstreambuf::underflow

      From cppreference.com
      <cpp‎ |io‎ |strstreambuf
       
       
       
       
      protected:
      virtual int_type underflow();
      (deprecated in C++98)
      (removed in C++26)

      Reads the next character from the get area of the buffer.

      If the input sequence has a read position available (gptr()< egptr(), returns(unsignedchar)(*gptr()).

      Otherwise, ifpptr() is not null andpptr()> egptr() (there is a put area and it is located after the get area), extends the end of the get area to include the characters that were recently written into the put area by incrementingegptr() to some value betweengptr() andpptr(), and then returns(unsignedchar)(*gptr()).

      Otherwise, returnsEOF to indicate failure.

      Contents

      [edit]Parameters

      (none)

      [edit]Return value

      The next character in the get area,(unsignedchar)(*gptr()) on success,EOF on failure.

      [edit]Example

      Run this code
      #include <iostream>#include <strstream> struct mybuf:std::strstreambuf{    int_type overflow(int_type c){std::cout<<"Before overflow(): size of the get area is "<< egptr()-eback()<<" size of the put area is "<< epptr()-pbase()<<'\n';        int_type rc= std::strstreambuf::overflow(c);std::cout<<"After overflow(): size of the get area is "<< egptr()-eback()<<" size of the put area is "<< epptr()-pbase()<<'\n';return rc;}     int_type underflow(){std::cout<<"Before underflow(): size of the get area is "<< egptr()-eback()<<" size of the put area is "<< epptr()-pbase()<<'\n';        int_type ch= std::strstreambuf::underflow();std::cout<<"After underflow(): size of the get area is "<< egptr()-eback()<<" size of the put area is "<< epptr()-pbase()<<'\n';if(ch==EOF)std::cout<<"underflow() returns EOF\n";elsestd::cout<<"underflow() returns '"<<char(ch)<<"'\n";return ch;}}; int main(){    mybuf sbuf;// read-write dynamic strstreambufstd::iostream stream(&sbuf); int n;    stream>> n;    stream.clear();    stream<<"123";    stream>> n;std::cout<< n<<'\n';}

      Possible output:

      Before underflow(): size of the get area is 0 size of the put area is 0After underflow(): size of the get area is 0 size of the put area is 0underflow() returns EOFBefore overflow(): size of the get area is 0 size of the put area is 0After overflow(): size of the get area is 0 size of the put area is 32Before underflow(): size of the get area is 0 size of the put area is 32After underflow(): size of the get area is 3 size of the put area is 32underflow() returns '1'Before underflow(): size of the get area is 3 size of the put area is 32After underflow(): size of the get area is 3 size of the put area is 32underflow() returns EOF123

      [edit]See also

      [virtual]
      reads characters from the associated input sequence to the get area
      (virtual protected member function ofstd::basic_streambuf<CharT,Traits>)[edit]
      [virtual]
      returns the next character available in the input sequence
      (virtual protected member function ofstd::basic_stringbuf<CharT,Traits,Allocator>)[edit]
      [virtual]
      reads from the associated file
      (virtual protected member function ofstd::basic_filebuf<CharT,Traits>)[edit]
      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 ofstd::basic_istream<CharT,Traits>)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/strstreambuf/underflow&oldid=170649"

      [8]ページ先頭

      ©2009-2025 Movatter.jp