std::basic_ios::tie
std::basic_ostream<CharT,Traits>* tie() const; | (1) | |
|---|---|---|
std::basic_ostream<CharT,Traits>* tie( std::basic_ostream<CharT,Traits>* str ); | (2) | |
管理绑定流。绑定流是与流缓冲区%28控制的序列同步的输出流。rdbuf()%29,即,flush()上的任何输入/输出操作之前调用绑定流。*this...
1%29返回当前绑定流。如果没有河溪,NULL会被归还。
2%29将当前绑定流设置为str返回操作前的绑定流。如果没有河溪,NULL会被归还。
参数
str | - | an output stream to set as the tied stream |
|---|
返回值
被捆绑的溪流,或NULL如果没有河系的话。
例外
%280%29
注记
默认情况下,标准流cin和cerr系在cout同样,它们的广泛对应方wcin和wcerr系在wcout...
例
二次
#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"二次
© cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

