I/O manipulators | ||||
Print functions(C++23) | ||||
C-style I/O | ||||
Buffers | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++20) | ||||
Streams | ||||
Abstractions | ||||
File I/O | ||||
String I/O | ||||
Array I/O | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
Synchronized Output | ||||
(C++20) | ||||
Types | ||||
Error category interface | ||||
(C++11) | ||||
(C++11) |
|
|
std::streamsize sputn(const char_type* s,std::streamsize count); | (1) | |
protected: virtualstd::streamsize xsputn(const char_type* s,std::streamsize count); | (2) | |
If the put area becomes full (pptr()== epptr()), it is unspecified whetheroverflow() is actually called or its effect is achieved by other means.
Contents |
(none)
The number of characters successfully written.
"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.
#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
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 565 | C++98 | xsputn() always calledoverflow() ifpptr()== epptr() | it does not actually need to be called |
invokesxsgetn() (public member function)[edit] |