Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::basic_stringbuf<CharT,Traits,Allocator>::setbuf

      From cppreference.com
      <cpp‎ |io‎ |basic stringbuf
       
       
       
       
      protected:
      virtualstd::basic_streambuf<CharT, Traits>* setbuf( char_type* s,std::streamsize n)

      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 clear thestd::string member currently used as the buffer and begin using the user-supplied character array of sizen, whose first element is pointed to bys, as the buffer and the input/output character sequence.

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

      Contents

      [edit]Parameters

      s - pointer to the first CharT in the user-provided buffer or null
      n - the number of CharT elements in the user-provided buffer or zero

      [edit]Return value

      this

      [edit]Notes

      The deprecated stream bufferstd::strstreambuf or the boost.IOStreams deviceboost::basic_array may be used to implement I/O buffering over a user-provided char array in portable manner.

      [edit]Example

      Test for the stringstream's setbuf functionality.

      Run this code
      #include <iostream>#include <sstream> int main(){std::ostringstream ss;char c[1024]={};    ss.rdbuf()->pubsetbuf(c,1024);    ss<<3.14<<'\n';std::cout<< c<<'\n';}

      Output:

      3.14 (on GNU g++/libstdc++ and SunPro C++/roguewave)<nothing> (on MS Visual Studio 2010, SunPro C++/stlport4, CLang++/libc++)

      [edit]See also

      invokessetbuf()
      (public member function ofstd::basic_streambuf<CharT,Traits>)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/basic_stringbuf/setbuf&oldid=158807"

      [8]ページ先頭

      ©2009-2025 Movatter.jp