public member function
<streambuf> <iostream>

std::basic_streambuf::pubsetbuf

basic_streambuf* pubsetbuf (char_type* s, streamsize n);
Set buffer array
Calls the protected virtual member setbuf with the same arguments s and n.

Member setbuf does nothing in basic_streambuf, but derived classes may override it to influence the object in a specific way for each derived class: both basic_filebuf and basic_stringbuf override this virtual member function to set the array of n characters pointed by s as the internal character sequence to be used by the stream buffer object (see basic_filebuf::setbuf and basic_stringbuf::setbuf).

Parameters

s, n
Arguments that may be used by overriding functions in derived classes.
Member type char_type is the type of the characters in the stream buffer (the first class template parameter).
streamsize is a signed integral type.

Return Value

In basic_streambuf, it always returns this.

Example

1
2
3
4
5
6
7
8
9
10
11
12
// set character buffer (pubsetbuf)
#include <fstream>      // std::fstream

int main () {
  char mybuffer [512];
  std::fstream filestr;
  filestr.rdbuf()->pubsetbuf(mybuffer,512);

  // operations with file stream here.

  return 0;
}

The code in this example sets a new buffer of 512 characters for filestr's stream buffer object.

Data races

Both this call and further calls to other member functions may access and/or modify the first n characters in the array pointed by s.
Modifies the stream buffer object.
Concurrent access to the same array or to the same stream buffer object may introduce data races.

Exception safety

Basic guarantee: if an exception is thrown, the stream buffer is in a valid state (this also applies to standard derived classes).

Invalid arguments cause undefined behavior.

See also