cin.tie与sync_with_stdio加速输入输出

在LeetCode上练习习题的时候每次AC之后都会去看别人的代码,几乎每次都能遇到cin.tie与sync_with_stdio。类似这样:

static auto x = [](){
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    return 0;
}();
class Solution {
public:
    string reverseString(string s) {
        reverse(s.begin(), s.end());
        return s;
    }
};

  代码中加粗的那部分,开始没在意,后头我就照着主体函数写,然而还是没有原答案快,我很纳闷,知乎搜索一下之后我也感叹我是怎么活到现在的。

在此不解释,一1切看原文,这是转载的别人的:http://www.hankcs.com/program/cpp/cin-tie-with-sync_with_stdio-acceleration-input-and-output.html

感谢前人的分享!

猜你喜欢

转载自www.cnblogs.com/love-DanDan/p/9147803.html