C ++ most people regard cin: sync () as misuse of the cache function, cinsync
One hundred degrees, most people think of the cin: sync () function as a function to clear the buffer. However, if we use the VS2017 compiler, we will find that the buffer cannot be cleared. Why?
Http://en.cppreference.com/w/cpp/io/basic_istream/sync
Follow the instructions in this standard document:
This function is used:Synchronizes the input buffer with the associated data source.
Then focus on:
As with readsome (), it is implementation-defined whether this function does anything with library-supplied streams. the intent is typically for the next read operation to pick up any changes that may have been made to the associated input sequence after the stream buffer last filled its get area. to achieve that,sync()
May empty the get area, or it may refill it, or it may do nothing. A notable exception is Visual Studio, where this operation discards the unprocessed input when called with a standard input stream.
This function is:Implementation-defined
Therefore, the implementation may not necessarily clear the buffer. The specific implementation is related to the compiler, so it does not have good portability. Use it with caution!
For details, refer to the specific instructions on this website!