名前空間
変種
操作

「cpp/io/basic ios/rdbuf」の版間の差分

提供: cppreference.com
< cpp‎ | io‎ | basic ios
(1版:Translate from the English version)
 
(1人の利用者による、間の3版が非表示)
1行: 1行:
{{tr_note}}
 
 
{{cpp/io/basic_ios/title|rdbuf}}
 
{{cpp/io/basic_ios/title|rdbuf}}
 
{{cpp/io/basic_ios/navbar}}
 
{{cpp/io/basic_ios/navbar}}
{{ddcl list begin}}
+
{{begin}}
{{ddcl list item | num = 1 |
+
{{| num = 1 |
std::basic_streambuf<CharT,Traits>* rdbuf() const;
+
std::basic_streambuf<CharT, Traits>* rdbuf() const;
 
}}
 
}}
{{ddcl list item | num = 2 |
+
{{| num = 2 |
std::basic_streambuf<CharT,Traits>* rdbuf( std::basic_streambuf<CharT,Traits>* sb );
+
std::basic_streambuf<CharT, Traits>* rdbuf( std::basic_streambuf<CharT, Traits>* sb );
 
}}
 
}}
{{ddcl list end}}
+
{{end}}
  
{{tr|関連付けられたストリームバッファを管理します.|Manages the associated stream buffer.}}
+
  
1) {{tr|関連付けられているストリームバッファを返します。関連付けられたストリームバッファが存在しない場合は、返品{{c|NULL}}.|Returns the associated stream buffer. If there is no associated stream buffer, returns {{c|NULL}}.}}
+
1
  
2) {{tr|{{tt|sb}}に関連付けられたストリームバッファを設定します。 {{tt|sb}}のエラー状態が{{c|sb.clear()}}を呼び出すことによってクリアされます。操作する前に、関連付けられたストリームバッファを返します。関連付けられたストリームバッファが存在しない場合は、返品{{c|NULL}}.|Sets the associated stream buffer to {{tt|sb}}. The error state of {{tt|sb}} is cleared by calling {{c|sb.clear()}}. Returns the associated stream buffer before the operation. If there is no associated stream buffer, returns {{c|NULL}}.}}
+
2{{tt|sb}} {{|clear()}}
  
===パラメータ===
+
======
{{param list begin}}
+
{{begin}}
{{param list item | sb |{{tr| ストリームバッファに関連付けることができます| stream buffer to associate to}}}}
+
{{| sb | }}
{{param list end}}
+
{{end}}
  
===値を返します===
+
======
{{tr|関連付けられたストリームバッファがなかった場合、関連付けられたストリームバッファ、または{{c|NULL}}.|The associated stream buffer, or {{c|NULL}} if there was no associated stream buffer.}}
+
  
 
===例外===
 
===例外===
{{tr|(なし)|(none)}}
+
()
  
 
===例===
 
===例===
 
{{example|
 
{{example|
 
|code=
 
|code=
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 
|output=
 
|output=
 +
 +
 
}}
 
}}
  
===も参照してください===
+
======
{{dcl list begin}}
+
{{begin}}
{{dcl list template | cpp/io/basic_ios/dcl list set_rdbuf}}
+
{{| cpp/io/basic_ios/set_rdbuf}}
{{dcl list end}}
+
{{end
 +
 
 +
}}

2018年6月2日 (土) 18:52時点における最新版

 
 
入出力ライブラリ
入出力マニピュレータ
Cスタイルの入出力
バッファ
(C++98で非推奨)
ストリーム
抽象
ファイル入出力
文字列入出力
配列入出力
(C++98で非推奨)
(C++98で非推奨)
(C++98で非推奨)
同期化出力
エラーカテゴリインタフェース
(C++11)
 
 
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 を置き換えます
(プロテクテッドメンバ関数) [edit]