Namespaces
Variants
Views
Actions

std::basic_streambuf::sputn, std::basic_streambuf::xsputn

From cppreference.com
< cpp‎ | io‎ | basic streambuf
Revision as of 18:55, 2 November 2012 by P12bot (Talk | contribs)

 
 
 
 

Template:ddcl list begin <tr class="t-dcl ">

<td >
std::streamsize sputn( const char_type* s, std::streamsize count );
</td>

<td > (1) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
protected:
virtual std::streamsize xsputn( const char_type* s, std::streamsize count );
</td>

<td > (2) </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

1) Calls xsputn(s, count) of the most derived class.

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 Template:rlpf. Writing stops when either count characters are written or a call to Template:rlpf would have returned traits::eof().

If the put area becomes full (pptr()==epptr()), this function may call Template:rlpf, or achieve the effect of calling overflow() by some other, unspecified, means.

Contents

Parameters

(none)

Return value

The number of characters successfully written.

Example

#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

See also

Template:cpp/io/basic streambuf/dcl list sgetn