istream::sync | public member function |
int sync ( ); |
Synchronize input buffer with source of characters
Synchronizes the buffer associated with the stream to its controlled input sequence. This effectively means that the unread characters in the buffer are discarded.
The function only has meaning for buffered streams, in which case it effectively calls the pubsync member of the streambuf object (rdbuf()->pubsync()) associated to the input sequence.
Parameters
noneReturn Value
If the stream is a buffered stream and the function is successful, zero is returned.If the stream is unbuffered, the function returns -1.
On error, the badbit flag is set (which can be checked with member bad). Also, depending on the values set through member exceptions, an exception may be thrown in this case.
Example
// read a file into memory #include <iostream> using namespace std; int main () { char first, second; cout << "Please, enter a word: "; first=cin.get(); cin.sync(); cout << "Please, enter another word: "; second=cin.get(); cout << "The first word began by " << first << endl; cout << "The second word began by " << second << endl; return 0; } |
This example demonstrates how sync behaves on cin, removing any unread character from the standard input queue of characters.
Basic template member declaration
( basic_istream<charT,traits> )
int sync ();
|
See also
ostream::flush | Flush output stream buffer (public member function) |
streambuf::pubsync | Synchronize stream buffer (public member function) |