Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::basic_streambuf<CharT,Traits>::pubsetbuf,std::basic_streambuf<CharT,Traits>::setbuf

      From cppreference.com
      <cpp‎ |io‎ |basic streambuf
       
       
       
      std::basic_streambuf
       
      public:
      basic_streambuf<CharT, Traits>* pubsetbuf( char_type* s,std::streamsize n)
      (1)
      protected:
      virtual basic_streambuf<CharT, Traits>* setbuf( char_type* s,std::streamsize n)
      (2)
      1) Callssetbuf(s, n) of the most derived class.
      2) The base class version of this function has no effect. The derived classes may override this function to allow removal or replacement of the controlled character sequence (the buffer) with a user-provided array, or for any other implementation-specific purpose.

      Contents

      [edit]Parameters

      s - pointer to the firstCharT in the user-provided buffer
      n - the number ofCharT elements in the user-provided buffer

      [edit]Return value

      1) The return value ofsetbuf(s, n).
      2)this

      [edit]Example

      Provides a 10k buffer for reading. On linux, the strace utility may be used to observe the actual number of bytes read.

      Run this code
      #include <fstream>#include <iostream>#include <string> int main(){int cnt=0;std::ifstream file;char buf[1024*10+1];     file.rdbuf()->pubsetbuf(buf, sizeof buf);     file.open("/usr/share/dict/words"); for(std::string line; getline(file, line);)++cnt; std::cout<< cnt<<'\n';}

      Possible output:

      356010

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 158C++98the default behavior ofsetbuf was only specified
      ifgptr() is not null and not equal toegptr()
      specified as no-op
      for all cases

      [edit]See also

      [virtual]
      attempts to replace the controlled character sequence with an array
      (virtual protected member function ofstd::basic_stringbuf<CharT,Traits,Allocator>)[edit]
      [virtual]
      provides user-supplied buffer or turns this filebuf unbuffered
      (virtual protected member function ofstd::basic_filebuf<CharT,Traits>)[edit]
      [virtual]
      attempts to replace the controlled character sequence with an array
      (virtual protected member function ofstd::strstreambuf)[edit]
      sets the buffer for a file stream
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/basic_streambuf/pubsetbuf&oldid=159844"

      [8]ページ先頭

      ©2009-2025 Movatter.jp