We are talking about the sync function in basic_istream.
For sync(), "my" standard says, at 27.6.1.3#36 (Unformatted input
functions):
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().
Strange. Which version is that, which doesn't say that it calls
rdbuf()->pubsync()? Functions in basic_istream have no effect
on the actual stream, except in so far as they call functions on
the streambuf.
In streambuf, pubsync() is required to call the virtual function
sync(), and the above is the definition of the semantics for
this function if the streambuf is a filebuf (the case for cin,
for example).
I know the semantics of fflush in C, and I agree that it's logical and
that it agrees to the English language, but I can't get your point:
fflush is one thing (and there is the corresponding flush method in C++
for ostreams), and sync is another thing (with a quite different English
meaning, too)
I'm trying to get at intent. Practically everything in iostream
is defined by mapping it to something appropriate in stdio.h;
formatting is defined in terms of printf formatters,
filebuf:
pen in terms of fopen, etc. So "intuitively", one
would expect sync to correspond to fflush (since that's about
the closest you can come in C). You're right, of course, that
the English word chosen does have different implications; I'm
not sure what it should mean with respect to keyboard input, but
you can't automatically say that it can't have meaning for input
in general. And C++ *does* require the implementation to
document what it does---it's not undefined behavior, as fflush
is in C. So if you're not worried about portability, and your
implementation defines it to do something which is useful to
you, by all means.
FWIW: in practice, I think most implementations---both of
filebuf::sync and fflush---simply discard any bytes that they
currently have in the buffer. If you're reading from a file,
this doesn't really correspond to what I would expect from the
English language word sync, but then, a lot of C and C++ (and
other languages, too) use English words in very special ways.
Under Unix (and Windows, too, I think), keyboard input is line
oriented by default; the system read will always stop at a new
line character (and not return until it sees one), regardless of
how many characters you requested. So *if* the buffer is large
enough, it will contain all of the line read, and sync will have
more or less the same effect as ignore. This effect is more or
less accidental, however, is not really guaranteed (at least by
the implementations I'm familiar with), and can fail in extreme
cases. (Try doing a setbuf with a buffer length of 1, or
entering over ten thousand characters, or whatever, in a line.)
It's not reliable.