cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : IOstream Library : ios : tie
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
IOstream Library
manipulators
classes:
· filebuf
· fstream
· ifstream
· ios
· iostream
· ios_base
· istream
· istringstream
· ofstream
· ostream
· ostringstream
· streambuf
· stringbuf
· stringstream
objects:
· cerr
· cin
· clog
· cout
types:
· fpos
· streamoff
· streampos
· streamsize
ios
· ios::ios
· ios::~ios
member functions:
· ios::bad
· ios::clear
· ios::copyfmt
· ios::eof
· ios::exceptions
· ios::fail
· ios::fill
· ios::good
· ios::imbue
· ios::init
· ios::narrow
· ios::operator!
· ios::operator void*
· ios::rdbuf
· ios::rdstate
· ios::setstate
· ios::tie
· ios::widen

-

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

// 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>)
basic_ostream<charT,traits> * tie () const;
basic_ostream<charT,traits> * tie ( basic_ostream<charT,traits> tiestr );

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us