ostream* tie ( ) const;
ostream* tie ( ostream* tiestr );

Get/set the tied stream.
  The first syntax returns the tied stream. The tie stream is a stream syncronized with the sequence controlled by the stream buffer that is automatically flushed when more characters are needed.
  The second syntax ties the object to tiestr and returns a pointer to the previously tied ostream object.
  By default, the standard objects cin, cerr and clog are tied to cout.


an output stream object to be tied to.

Return Value.
  A pointer to the stream object tied before the call, or if none, a null pointer.


// redefine tied object
#include <iostream>
#include <fstream>
using namespace std;

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

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


  return 0;

Basic template member declaration ( basic_ios<charT,traits> ):
basic_ostream<charT,traits> * tie () const;
basic_ostream<charT,traits> * tie ( basic_ostream<charT,traits> tiestr );

See also.
  ios class

© The C++ Resources Network, 2001