Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::strstreambuf::setbuf

      From cppreference.com
      <cpp‎ |io‎ |strstreambuf
       
       
       
       
      protected:
      virtual streambuf* setbuf(char* s,std::streamsize n);
      (deprecated in C++98)
      (removed in C++26)

      Ifs is a null pointer andn is zero, this function has no effect.

      Otherwise, the effect is implementation-defined: some implementations do nothing, while some implementations deallocate the dynamic member array used as the buffer and begin using the user-supplied character array of sizen, whose first element is pointed to bys.

      This function is protected virtual, it may only be called throughpubsetbuf() or from member functions of a user-defined class derived fromstd::strstreambuf.

      Contents

      [edit]Parameters

      s - pointer to the first byte in the user-provided buffer
      n - the number of bytes in the user-provided buffer

      [edit]Return value

      this

      [edit]Example

      Implementation test to check ifsetbuf() is supported on a dynamic strstream (output obtained with Sun Studio):

      Run this code
      #include <iostream>#include <strstream> int main(){char a[100]={};std::strstream str;    str.rdbuf()->pubsetbuf(a, sizeof a);    str<<"Test string"<<std::ends;std::cout<<"user-provided buffer holds\""<< a<<"\"\n";}

      Possible output:

      user-provided buffer holds "Test string"

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      LWG 66C++98the effect ofsetbuf() was "performs an operation that is
      defined separately for each class derived fromstrstreambuf",
      but there are no classes derived fromstrstreambuf
      the effect is
      implementation-defined

      [edit]See also

      invokessetbuf()
      (public member function ofstd::basic_streambuf<CharT,Traits>)[edit]
      [virtual]
      replaces the buffer with user-defined array, if permitted
      (virtual protected member function ofstd::basic_streambuf<CharT,Traits>)[edit]
      [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]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/strstreambuf/setbuf&oldid=170652"

      [8]ページ先頭

      ©2009-2025 Movatter.jp