std::basic_ios<CharT,Traits>::rdbuf
提供: cppreference.com
<tbody>
</tbody>
std::basic_streambuf<CharT, Traits>* rdbuf() const; |
(1) | |
std::basic_streambuf<CharT, Traits>* rdbuf( std::basic_streambuf<CharT, Traits>* sb ); |
(2) | |
紐付けられているストリームバッファを管理します。
1) 紐付けられているストリームバッファを返します。 紐付けられているストリームバッファがない場合はヌルポインタを返します。
2) 紐付けられているストリームバッファを
sb に設定します。 エラー状態は clear() を呼ぶことによってクリアされます。 この操作の前に紐付けられていたストリームバッファを返します。 紐付けられていたストリームバッファがない場合はヌルポインタを返します。引数
| sb | - | 紐付けるストリームバッファ |
戻り値
紐付けられていたストリームバッファ、または紐付けられていたストリームバッファがなかった場合はヌルポインタ。
例外
(なし)
例
Run this code
#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
関連項目
エラー状態をクリアせずに rdbuf を置き換えます (プロテクテッドメンバ関数) |