ios::tie
ostream* tie ( ) const; ostream* tie ( ostream* tiestr ); | ios |
cplusplus.com |
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.
Parameters.
Return Value.
A pointer to the stream object tied before the call, or if none, a null pointer.
Example.
// redefine tied object #include <iostream> #include <fstream> using namespace std; int main () { ostream *prevstr; ofstream filestr; filestr.open ("test.txt"); *cin.tie() << "This is inserted into cout"; prevstr = cin.tie (&filestr); *cin.tie() << "This is inserted into file"; cin.tie (prevstr); filestr.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 ); |
See also.
ios class