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.
[edit] Parameters s - pointer to the firstCharT
in the user-provided buffer n - the number of CharT
elements in the user-provided buffer [edit] Return value
1) The return value of setbuf(s, n).
2) this
[edit] ExampleProvides 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:
[edit] Defect reportsThe 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 specified
std::basic_stringbuf<CharT,Traits,Allocator>
) [edit] provides user-supplied buffer or turns this filebuf unbuffered
std::basic_filebuf<CharT,Traits>
) [edit] attempts to replace the controlled character sequence with an array
std::strstreambuf
) [edit] sets the buffer for a file stream
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4