Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::basic_streambuf<CharT,Traits>::setp

      From cppreference.com
      <cpp‎ |io‎ |basic streambuf
       
       
       
      std::basic_streambuf
       
      protected:
      void setp( char_type* pbeg, char_type* pend);

      Sets the values of the pointers defining the put area.

      After the call,pbase()== pbeg,pptr()== pbeg andepptr()== pend are alltrue.

      If any of[pbegpend) is not avalid range, the behavior is undefined.

      Contents

      [edit]Parameters

      pbeg - pointer to the new beginning of the put area
      pend - pointer to the new end of the put area

      [edit]Example

      Run this code
      #include <array>#include <cstddef>#include <iostream> // Buffer for std::ostream implemented by std::arraytemplate<std::size_t size,class CharT=char>struct ArrayedStreamBuffer:std::basic_streambuf<CharT>{using Base=std::basic_streambuf<CharT>;using char_type=typename Base::char_type;     ArrayedStreamBuffer(){// put area pointers to work with “buffer”        Base::setp(buffer.data(), buffer.data()+ size);} void print_buffer(){for(char_type i: buffer){if(i==0)std::cout<<"\\0";elsestd::cout<< i;std::cout<<' ';}std::cout<<'\n';} private:std::array<char_type, size> buffer{};// value-initialize “buffer”}; int main(){    ArrayedStreamBuffer<10> streambuf;std::ostream stream(&streambuf);     stream<<"hello";    stream<<",";     streambuf.print_buffer();}

      Output:

      h e l l o , \0 \0 \0 \0

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      LWG 4023C++98setp did not require the output sequence to be a valid rangerequires

      [edit]See also

      repositions the beginning, next, and end pointers of the input sequence
      (protected member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/basic_streambuf/setp&oldid=172940"

      [8]ページ先頭

      ©2009-2025 Movatter.jp