Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::basic_filebuf<CharT,Traits>::underflow

      From cppreference.com
      <cpp‎ |io‎ |basic filebuf
       
       
       
       
      protected:
      virtual int_type underflow()

      Reads more data into the input area.

      Behaves like the base classstd::basic_streambuf::underflow, except that to read the data from the associated character sequence (the file) into the get area, first reads the bytes from the file into a temporary buffer (allocated as large as necessary), then usesstd::codecvt::in of the imbued locale to convert the external (typically, multibyte) representation to the internal form which is then used to populate the get area. The conversion may be skipped if the locale'sstd::codecvt::always_noconv returnstrue.

      Contents

      [edit]Parameters

      (none)

      [edit]Return value

      Traits::to_int_type(*gptr()) (the first character of the pending sequence) in case of success, orTraits::eof() in case of failure.

      [edit]Example

      Run this code
      #include <fstream>#include <iostream> struct mybuf:std::filebuf{int underflow(){std::cout<<"Before underflow(): size of the get area is "<< egptr()-eback()<<" with "<< egptr()-gptr()<<" read positions available\n";int rc= std::filebuf::underflow();std::cout<<"underflow() returns "<< rc<<".\nAfter the call, "<<"size of the get area is "<< egptr()-eback()<<" with "<< egptr()-gptr()<<" read positions available\n";return rc;}}; int main(){    mybuf buf;    buf.open("test.txt",std::ios_base::in);std::istream stream(&buf);while(stream.get());}

      Possible output:

      Before underflow(): size of the get area is 0 with 0 read positions availableunderflow() returns 73.After the call, size of the get area is 110 with 110 read positions availableBefore underflow(): size of the get area is 110 with 0 read positions availableunderflow() returns -1.After the call, size of the get area is 0 with 0 read positions available

      [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 a character from the input sequence without advancing the next pointer
      (virtual protected member function ofstd::strstreambuf)[edit]
      [virtual]
      reads from the associated file and advances the next pointer in the get area
      (virtual protected member function)[edit]
      [virtual]
      writes characters to the associated file from the put area
      (virtual protected member function)[edit]
      reads one character from the input sequence without advancing the sequence
      (public member function ofstd::basic_streambuf<CharT,Traits>)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/basic_filebuf/underflow&oldid=158144"

      [8]ページ先頭

      ©2009-2025 Movatter.jp