std::basic_...buf::xsputn(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

🌸 NAME 🌸

hey bestie πŸ’… welcome to the std::basic_...buf::xsputn(3) page from the C++ Standard Libary manual β€” section 3, no cap. This one is all about std::basic_streambuf::sputn,std::basic_streambuf::xsputn β€” like, the full NAME situation is std::basic_streambuf::sputn,std::basic_streambuf::xsputn β€” std::basic_streambuf::sputn,std::basic_streambuf::xsputn. slay ✨


✨ Synopsis ✨

std::streamsize sputn( const char_type* s, std::streamsize count );

(1)

protected:
virtual std::streamsize xsputn( const char_type* s, std::streamsize count );

(2)

  1. Calls xsputn(s, count) of the most derived class. main character energy πŸ‘‘
  2. Writes count characters to the output sequence from the character array whose first element is pointed to by s. The characters are written as if by repeated calls to sputc(). Writing stops when either count characters are written or a call to sputc() would have returned Traits::eof().

If the put area becomes full (pptr() == epptr()), it is unspecified whether overflow() is actually called or its effect is achieved by other means. iykyk πŸ‘€


πŸŽ€ Parameters πŸŽ€

(none) β€” literally none, bestie. nothing to pass, no stress 🫢


πŸ’– Return value πŸ’–

The number of characters successfully written. periodt πŸ’…


πŸ¦‹ Notes πŸ¦‹

The phrase "achieved by other means" permits bulk I/O without intermediate buffering: that is how std::ofstream::write() simply passes the pointer to the suitable system call in some implementations. highkey iconic πŸ”₯


🌈 Example 🌈

The page literally says // Run this code, and here's the code exactly:

#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 14
The output sequence contains This is a test
The call to sputn() on an input stream returned 0

🩹 Defect reports 🩹

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

  • DR: LWG 565
    • Applied to: C++98
    • Behavior as published: xsputn() always called overflow() if pptr() == epptr()
    • Correct behavior: it does not actually need to be called

retroactive glow-up, we love to see it πŸ’œ


πŸ”­ See also πŸ”­

  • sgetn invokes xsgetn() (public member function)

okay bye bestie πŸ«ΆπŸ’– this page came from http://cppreference.com, dated 2024.06.10, and yes the title is std::basic_...buf::xsputn(3) β€” mwah πŸŽ€βœ¨

πŸ“¦ where this page comes from