首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

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

注记

默认情况下,标准流cincerr系在cout同样,它们的广泛对应方wcinwcerr系在wcout...

二次

代码语言:javascript
复制
#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";
}

二次

产出:

二次

代码语言:javascript
复制
Result before tie(): "0"
Result after tie(): "Hello"

二次

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com