public member function
<istream> <iostream>
std::basic_istream::syncSynchronize input buffer
Synchronizes the associated stream buffer with its controlled input sequence.Specifics of the operation depend on the particular implementation of the stream buffer object associated to the stream.
Internally, the function accesses the input sequence by first constructing a sentry object (with noskipws set to true
). Then (if good), it calls pubsync on its associated stream buffer object (if rdbuf is null, the function returns -1
instead). Finally, it destroys the sentry object before returning.
If the call to pubsync fails (i.e., it returns -1
), the function sets the badbit flag, and returns -1
. Otherwise it returns zero, indicating success.
Notice that the called function may succeed when no action is performed, if that is the behavior defined for the stream buffer object on synchronization.
Calling this function does not alter the value returned by gcount.
-1
.
Errors are signaled by modifying the internal state flags:
-1
, or some other error occurred on the stream (such as when the function catches an exception thrown by an internal operation).
If the operation sets an internal state flag that was registered with member exceptions, the function throws an exception of member type failure.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// syncing input stream
#include <iostream> // std::cin, std::cout
int main () {
char first, second;
std::cout << "Please, enter a word: ";
first = std::cin.get();
std::cin.sync();
std::cout << "Please, enter another word: ";
second = std::cin.get();
std::cout << "The first word began by " << first << '\n';
std::cout << "The second word began by " << second << '\n';
return 0;
}
Possible output:
Please, enter a word: test Please enter another word: text The first word began by t The second word began by t
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4