C + + input and output stream accelerator, turn off Sync stream, Ios::sync_with_stdio (false) and Cin.tie (0)

Source: Internet
Author: User

Leetcode practice, you will always find that the code with short running times is similar:

Static int x=[] () {    Std::ios::sync_with_stdio (false);    Cin.tie (NULL);     return 0 ;} ();

So I have a look at these lines of code:

Std::ios::sync_with_stdio (false);

This function is a "compatibility stdio" switch, C + + in order to be compatible with C, to ensure that the program in use of std::p rintf and std::cout without confusion, the output stream is tied together.

Cin,cout is inefficient because the first thing to output to buffer, and then output, resulting in reduced efficiency, and this statement can be used to eliminate iostream input and output cache , can save a lot of time, so that efficiency and scanf and printf, It should also be noted that the header files used by scanf and printf should be stdio.h instead of iostream.

Cin.tie (NULL);

The tie is a function that binds two stream, and the null argument returns the current output stream pointer

Reference article: https://www.cnblogs.com/PrayG/p/5749832.html

C + + input and output stream accelerator, turn off Sync stream, Ios::sync_with_stdio (false) and Cin.tie (0)

Related Article

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.