std::basic_streambuf<CharT,Traits>::pubsetbuf, std::basic_streambuf<CharT,Traits>::setbuf

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

# Declarations

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

# Parameters

# Example

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

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 158C++98the default behavior of setbuf was only specifiedif gptr() is not null and not equal to egptr()specified as no-opfor all cases

# See also