Most people in C + + treat Cin::sync () as a misuse of the buffer function

Source: Internet
Author: User

100 degrees, most people will directly understand the Cin::sync () function as a function of emptying the buffer, but if it is on the VS2017 compiler, it will find that the buffer cannot be emptied, why?

Http://en.cppreference.com/w/cpp/io/basic_istream/sync

According to the instructions in this standard document:

The function acts as:synchronizes the input buffer with the associated data source.

Then focus on:

as with Readsome (), it's 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 so may has been made to the associated input Sequence after the stream, buffer last filled its get area. To achieve that, could sync() empty the get area, or it could refill it, or it may does nothing. A notable exception is Visual Studio, where this operation discards the unprocessed input when called with a standard Inpu T stream.

This function is: implementation-defined


So the implementation, can not be able to clear the buffer, the specific implementation with the compiler-related, so do not have a good transplant, use with caution!

Specific information can be referred to the specific description of the site!

Most people in C + + treat Cin::sync () as a misuse of the buffer function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.