std::basic_...buf::xsputn(3)
πΈ 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)
- Calls
xsputn(s, count)of the most derived class. main character energy π - Writes
countcharacters 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 eithercountcharacters are written or a call tosputc()would have returnedTraits::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
- Applied to:
retroactive glow-up, we love to see it π
π See also π
sgetninvokesxsgetn()(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
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms