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) |
|
|
public: basic_streambuf<CharT, Traits>* pubsetbuf( char_type* s,std::streamsize n) | (1) | |
protected: virtual basic_streambuf<CharT, Traits>* setbuf( char_type* s,std::streamsize n) | (2) | |
Contents |
s | - | pointer to the firstCharT in the user-provided buffer |
n | - | the number ofCharT elements in the user-provided buffer |
Provides 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[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';}
Possible output:
356010
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 158 | C++98 | the default behavior ofsetbuf was only specifiedifgptr() is not null and not equal toegptr() | specified as no-op for all cases |
[virtual] | attempts to replace the controlled character sequence with an array (virtual protected member function of std::basic_stringbuf<CharT,Traits,Allocator> )[edit] |
[virtual] | provides user-supplied buffer or turns this filebuf unbuffered (virtual protected member function of std::basic_filebuf<CharT,Traits> )[edit] |
[virtual] | attempts to replace the controlled character sequence with an array (virtual protected member function of std::strstreambuf )[edit] |
sets the buffer for a file stream (function)[edit] |