std::basic_ios<CharT,Traits>::tie
提供: cppreference.com
std::basic_ostream<CharT,Traits>* tie() const; |
(1) | |
std::basic_ostream<CharT,Traits>* tie( std::basic_ostream<CharT,Traits>* str ); |
(2) | |
結び付けられているストリームを管理します。 結び付けられているストリームは、ストリームバッファ (rdbuf()) によって制御されるシーケンスと同期する出力ストリームです。 つまり、 *this に対するあらゆる入出力操作の前に、結び付けられているストリームに対して flush() を呼びます。
1) 現在紐付けられているストリームを返します。 結び付けられているストリームがない場合は、ヌルポインタが返される。
2) 現在紐付けられているストリームを
str
に設定します。 この操作の前に結び付けられていたストリームを返します。 結び付けられていたストリームがなかった場合はヌルポインタが返されます。目次 |
[編集] 引数
str | - | 結び付ける出力ストリーム |
[編集] 戻り値
結び付けられていたストリーム、または結び付けられていたストリームがない場合はヌルポインタ。
[編集] 例外
(なし)
[編集] ノート
デフォルトでは、標準ストリーム cout
は cin
および cerr
によって tie されています。 同様に、ワイド文字版の wcout
は wcin
および wcerr
によって tie されています。
[編集] 例
Run this code
#include <iostream> #include <fstream> #include <string> int main() { std::ofstream os("test.txt"); std::ifstream is("test.txt"); std::string value("0"); os << "Hello"; is >> value; std::cout << "Result before tie(): \"" << value << "\"\n"; is.clear(); is.tie(&os); is >> value; std::cout << "Result after tie(): \"" << value << "\"\n"; }
出力:
Result before tie(): "0" Result after tie(): "Hello"