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) |
Member functions | ||||
State functions | ||||
Formatting | ||||
Miscellaneous | ||||
basic_ios::rdbuf | ||||
Protected member functions | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) |
std::basic_streambuf<CharT, Traits>* rdbuf()const; | (1) | |
std::basic_streambuf<CharT, Traits>* rdbuf(std::basic_streambuf<CharT, Traits>* sb); | (2) | |
Manages the associated stream buffer.
Contents |
sb | - | Stream buffer to associate to. |
The associated stream buffer, or a null pointer if there was no associated stream buffer.
May throw implementation-defined exceptions.
#include <iostream>#include <sstream> int main(){std::ostringstream local;auto cout_buff=std::cout.rdbuf();// save pointer to std::cout buffer std::cout.rdbuf(local.rdbuf());// substitute internal std::cout buffer with// buffer of 'local' object // now std::cout work with 'local' buffer// you don't see this messagestd::cout<<"some message"; // go back to old bufferstd::cout.rdbuf(cout_buff); // you will see this messagestd::cout<<"back to default buffer\n"; // print 'local' contentstd::cout<<"local content: "<< local.str()<<"\n";}
Output:
back to default bufferlocal content: some message
replaces therdbuf without clearing its error state(protected member function)[edit] |