- 当输入流与输出流绑在一起时,任何读输入流的尝试都将首先刷新其输出流关联的缓冲区
- 如果在调用tie函数时传递实参0,则打破该流上已存在的捆绑
#include "stdafx.h"
#include
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cin.tie(&cout);//illusstration only:the library ties cin and cout for us
ostream *old_tie=cin.tie();
cin.tie(0);//break tie to cout,cout no longer flushed when cin is read
cin.tie(&cerr);//ties cin and cerr,not necessarily a good idea!
cin.tie(0);//break tie between cin and cerr
cin.tie(&cout);//restablish normal tie between cin and cout
system("pause");
return 0;
}
输入输出流捆绑解析
本文介绍了C++中输入输出流的捆绑机制,包括如何通过调用tie函数来实现输入流与输出流之间的关联与解除关联。文章展示了具体的代码示例,演示了如何将标准输入流cin与标准输出流cout进行捆绑及取消捆绑。
1万+

被折叠的 条评论
为什么被折叠?



