「cpp/io/basic ios/tie」の版間の差分
提供: cppreference.com
細 (Use {{lc}}. Update links. Various fixes.) |
|||
(2人の利用者による、間の3版が非表示) | |||
1行: | 1行: | ||
− | |||
{{cpp/io/basic_ios/title|tie}} | {{cpp/io/basic_ios/title|tie}} | ||
{{cpp/io/basic_ios/navbar}} | {{cpp/io/basic_ios/navbar}} | ||
11行: | 10行: | ||
{{dcl end}} | {{dcl end}} | ||
− | {{ | + | {{|rdbuf()}}{{c|*this}} {{c|flush()}} |
− | 1 | + | 1 |
− | 2 | + | 2{{tt|str}} |
− | === | + | ====== |
{{par begin}} | {{par begin}} | ||
− | {{par | str | | + | {{par | str | }} |
{{par end}} | {{par end}} | ||
− | === | + | ====== |
− | + | ||
===例外=== | ===例外=== | ||
− | + | () | |
===ノート=== | ===ノート=== | ||
− | + | デフォルトでは、標準ストリーム {{tt|cout}} {{tt|cin}} {{tt|cerr}} {{tt|}} {{tt|wcin}} {{tt|wcerr}} | |
===例=== | ===例=== | ||
{{example| | {{example| | ||
|code= | |code= | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
|output= | |output= | ||
+ | |||
+ | |||
}} | }} | ||
− | + | deenesfritptruzh | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + |
2019年11月29日 (金) 00:55時点における最新版
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"