Look at C + + primer today and see the Ios::tie () function. Do not understand its meaning, and do not know the role. So I checked the internet.
The definition given by cplusplus.com is:
ostream* tie () const;//Returns a pointer to the bound output stream.
ostream* Tie (ostream* tiestr); The tiestr points to the output stream that is bound to the object and returns the last bound output stream pointer.
What do you mean?
This means that for an iOS (input and output stream) object, you Can "bind" an output stream to it. Executes without parameters, returns the output stream pointer of "bind", sets the bound object back with an output stream pointer as a parameter, and returns the predecessor bound object (pointer).
But what is "binding"?
For example, for the following program:
#include <iostream> #include <fstream>using namespace Std;int main () { ofstream ofs; Ofs.open ("test.txt"); Cin.tie (&OFS); Comment out this line try *cin.tie () << "There'll be some text:"; Equivalent to OFS << "There'll be some text"; char c; while (CIN >> c) { ofs << C; } Ofs.close (); return 0;}
Under the Linux Watch command (under Windows do not know anything similar, if not to use this method: Manually turn off and then open) real-time view test.txt files, you will find every time you hit a few words in the terminal press ENTER, Test.txt file in the text more than a few.
And if you comment out the line labeled in the code, you will find that Test.txt will only appear when the program is running at the end of the run (under Linux by pressing ctrl+d,windows with the CTRL + Z end input).
This is the effect of "binding", whenever a "bound" object is inconsistent or output operation, will automatically refresh the "bound" of the object's buffer, in order to achieve real-time effect
Go C + + 's tie () function