std::basic_ios<CharT,Traits>::rdbuf
From cppreference.com
| 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 | - | 関連付けるストリームバッファ。 |
[編集] 戻り値
関連するストリームバッファ。関連するストリームバッファがなかった場合はヌルポインタ。
[編集] 例外
実装定義の例外をスローする場合があります。
[編集] 例
このコードを実行
#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を置き換えます。(保護メンバ関数) |