J
john
I am reading TC++PL3 and on page 644 it is mentioned:
"Flushing an istream is done using sync(). This cannot always be done
right. For some kinds of streams, we would have to reread characters
from the real source - and that is not always possible or desirable.
Consequently, sync() returns 0 if it succeeded. If it failed, it sets
ios_base::badbit (21.3.3) and returns -1. Again, setting badbit might
trigger an exception (21.3.6). A sync() on a buffer attached to an
ostream flushes the buffer to output".
So, what exactly should we expect from an call of sync() on an istream?
Making its streambuf to lose all its contents?
The code:
#include <iostream>
int main()
{
using namespace std;
char c;
cin>> c;
cout<< c<< endl;
int sync_failure= cin.sync();
cout<< sync_failure<< endl;
cin >> c;
cout<< c<< endl;
}
in my system produces:
[john@localhost src]$ ./foobar-cpp
test
t
0
e
[john@localhost src]$
"Flushing an istream is done using sync(). This cannot always be done
right. For some kinds of streams, we would have to reread characters
from the real source - and that is not always possible or desirable.
Consequently, sync() returns 0 if it succeeded. If it failed, it sets
ios_base::badbit (21.3.3) and returns -1. Again, setting badbit might
trigger an exception (21.3.6). A sync() on a buffer attached to an
ostream flushes the buffer to output".
So, what exactly should we expect from an call of sync() on an istream?
Making its streambuf to lose all its contents?
The code:
#include <iostream>
int main()
{
using namespace std;
char c;
cin>> c;
cout<< c<< endl;
int sync_failure= cin.sync();
cout<< sync_failure<< endl;
cin >> c;
cout<< c<< endl;
}
in my system produces:
[john@localhost src]$ ./foobar-cpp
test
t
0
e
[john@localhost src]$