Actually, I dont know, or fully understand, the details either.Can someone explain with more details, please?
I've been digging up the C++ standard, and so far have found:
From basic_istream (27.6.1.3):
int sync();
Effects: Behaves as an unformatted input function (as described in 27.6.1.3, paragraph 1), except that it
does not count the number of characters extracted and does not affect the value returned by subsequent
calls to gcount(). After constructing a sentry object, if rdbuf() is a null pointer, returns -1 . Otherwise,
calls rdbuf()->pubsync() and, if that function returns -1 calls setstate(badbit)
(which may throw ios_base::failure (27.4.4.3), and returns -1. Otherwise, returns zero.
From basic_streambuf (27.5.2.2.2):
int pubsync();
Returns: sync().
From basic_streambuf (27.5.2.4.2):
int sync();
Effects: Synchronizes the controlled sequences with the arrays. That is, if pbase() is non-null the characters
between pbase() and pptr() are written to the controlled sequence. The pointers may then
be reset as appropriate.
Returns: -1 on failure. What constitutes failure is determined by each derived class (27.8.1.4).
Default behavior: Returns zero.
From basic_streambuf (27.5.2.3.2):
char_type* pbase() const;
Returns: The beginning pointer for the output sequence.
char_type* pptr() const;
Returns: The next pointer for the output sequence.
Somehow cin.sync() effectively seems to flush the input buffer, from what I see.



LinkBack URL
About LinkBacks



