Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::basic_streambuf<CharT,Traits>::sputn,std::basic_streambuf<CharT,Traits>::xsputn

      From cppreference.com
      <cpp‎ |io‎ |basic streambuf
       
       
       
      std::basic_streambuf
       
      std::streamsize sputn(const char_type* s,std::streamsize count);
      (1)
      protected:
      virtualstd::streamsize xsputn(const char_type* s,std::streamsize count);
      (2)
      1) Callsxsputn(s, count) of the most derived class.
      2) Writescount characters to the output sequence from the character array whose first element is pointed to bys. The characters are written as if by repeated calls tosputc(). Writing stops when eithercount characters are written or a call tosputc() would have returnedTraits::eof().

      If the put area becomes full (pptr()== epptr()), it is unspecified whetheroverflow() is actually called or its effect is achieved by other means.

      Contents

      [edit]Parameters

      (none)

      [edit]Return value

      The number of characters successfully written.

      [edit]Notes

      "achieved by other means" permits bulk I/O without intermediate buffering: that is howstd::ofstream::write() simply passes the pointer to the suitable system call in some implementations.

      [edit]Example

      Run this code
      #include <iostream>#include <sstream> int main(){std::ostringstream s1;std::streamsize sz= s1.rdbuf()->sputn("This is a test",14);    s1<<'\n';std::cout<<"The call to sputn() returned "<< sz<<'\n'<<"The output sequence contains "<< s1.str(); std::istringstream s2;    sz= s2.rdbuf()->sputn("This is a test",14);std::cout<<"The call to sputn() on an input stream returned "<< sz<<'\n';}

      Output:

      The call to sputn() returned 14The output sequence contains This is a testThe call to sputn() on an input stream returned 0

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      LWG 565C++98xsputn() always calledoverflow() ifpptr()== epptr()it does not actually need to be called

      [edit]See also

      invokesxsgetn()
      (public member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/basic_streambuf/sputn&oldid=148677"

      [8]ページ先頭

      ©2009-2025 Movatter.jp