ios::tie


public member function
ostream* tie ( ) const;
ostream* tie ( ostream* tiestr );

Get/set the tied stream

The first function version returns a pointer to the tied output stream.

The second function version ties the object to tiestr and returns a pointer to the object previously tied.

The tied stream is another output stream object which is flushed before each i/o operation in this stream object.

By default, the standard objects cin, cerr and clog are tied to cout, and their wide character counterparts (wcin, wcerr and wclog) to wcout.

Parameters

tiestr
an output stream object to tie.


Return Value

A pointer to the stream object tied before the call, or a null pointer in case the stream was not tied.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// redefine tied object
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ostream *prevstr;
  ofstream ofs;
  ofs.open ("test.txt");

  cout << "tie example:" << endl;

  *cin.tie() << "This is inserted into cout";
  prevstr = cin.tie (&ofs);
  *cin.tie() << "This is inserted into the file";
  cin.tie (prevstr);

  ofs.close();

  return 0;
}


Basic template member declaration

(basic_ios<charT,traits>)
1
2
basic_ostream<charT,traits> * tie () const;
basic_ostream<charT,traits> * tie ( basic_ostream<charT,traits> tiestr );