在线文档教程
C++
输入/输出 | Input/output

std::basic_ios::rdbuf

性病:基本[医]IOS::rdbuf

std::basic_streambuf* rdbuf() const;(1)
std::basic_streambuf<CharT, Traits>* rdbuf( std::basic_streambuf<CharT, Traits>* sb (2)

管理关联的流缓冲区。

1%29返回关联的流缓冲区。如果没有关联的流缓冲区,则返回NULL...

2%29将关联的流缓冲区设置为sb.错误状态通过调用clear()返回操作前的关联流缓冲区。如果没有关联的流缓冲区,则返回NULL...

参数

sb-stream buffer to associate to

返回值

关联的流缓冲区,或NULL如果没有关联的流缓冲区。

例外

%280%29

二次

#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 message std::cout << "some message"; // go back to old buffer std::cout.rdbuf(cout_buff // you will see this message std::cout << "back to default buffer\n"; // print 'local' content std::cout << "local content: " << local.str() << "\n"; }

二次

产出:

二次

back to default buffer local content: some message

二次

另见

set_rdbufreplaces the rdbuf without clearing its error state (protected member function)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/io/basic[医]IOS/rdbuf