Namespaces
Variants
Views
Actions

std::basic_streambuf::pubsetbuf, std::basic_streambuf::setbuf

From cppreference.com
< cpp‎ | io‎ | basic streambuf
Revision as of 11:30, 23 March 2013 by SuperBoi45 (Talk | contribs)

 
 
 
 

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

<td >
basic_streambuf<CharT, Traits>* pubsetbuf( char_type* s, std::streamsize n )
</td>

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

<td >
protected:
virtual basic_streambuf<CharT, Traits>* setbuf( char_type* s, std::streamsize n )
</td>

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

1) Calls setbuf(s, n) of the most derived class

2) The base class version of this function has no effect. The derived classes may override this function to allow removal or replacement of the controlled character sequence (the buffer) with a user-provided array, or for any other implementation-specific purpose.

Contents

Parameters

s - pointer to the first byte in the user-provided buffer
n - the number of bytes in the user-provided buffer

Return value

*this

Example

provide a 10k buffer for reading. On linux, the strace utility may be used to observe the actual number of bytes read

#include <fstream>
#include <iostream>
#include <string>
 
int main()
{
    int cnt = 0;
    std::ifstream file;
    char buf[10241];
 
    file.rdbuf()->pubsetbuf(buf, sizeof buf);
 
    file.open("/usr/share/dict/words");
 
    for (std::string line; getline(file, line);) {
        cnt++;
    }
 
    std::cout << cnt << '\n';
}


See also

Template:cpp/io/basic filebuf/dcl list setbuf