C++ std::ios::tie
生活随笔
收集整理的這篇文章主要介紹了
C++ std::ios::tie
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
一 作用
獲取、設(shè)置綁定流
二 函數(shù)申明
| get(1) | ostream* tie() const | 返回指向綁定輸出流的指針 |
| set(2) | ostream* tie(ostream* tiestr) | 將對(duì)象綁定到輸出流tiestr,并返回之前綁定流的指針(如果有的話);若之前未綁定,返回空指針 |
三 注意
The?tied stream?is an output stream object which is flushed?before each i/o operation in this stream object.
即:綁定的輸出流在流對(duì)象的輸入/輸出操作前會(huì)刷新。
1 c++98
默認(rèn)情況下,cin綁定到cout,wcin綁定到wcout。庫實(shí)現(xiàn)可以在初始化時(shí)綁定其他標(biāo)準(zhǔn)流。
2 c++11
默認(rèn)情況下,標(biāo)準(zhǔn)窄流cin和cerr與cout綁定,它們的寬字符對(duì)應(yīng)(wcin和wcerr)綁定到wcout。 庫實(shí)現(xiàn)也可以綁定clog和wclog。
四 舉例
#include <iostream> #include <fstream>/* * c++ ios::tie demo */using std::cin;int main() {std::ofstream ofs;ofs.open("test.txt");// 綁定流是一個(gè)輸出流對(duì)象,它在這個(gè)流對(duì)象中的每個(gè)i/o操作之前刷新。// 該條語句能做到實(shí)時(shí)刷新cin.tie(&ofs);char c;while (cin >> c){ofs << c;}ofs.close();system("pause"); }五 參考
std::ios::tie
總結(jié)
以上是生活随笔為你收集整理的C++ std::ios::tie的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《老板最爱的简历表》阅读
- 下一篇: c++中的ignore和tie