std::ios::sync_with_stdio(false);

 

在竞赛的时候,遇到大量数据输入输出的时候。我们一般选择scanf和printf,因为cin和cout的效率相对来说比较低。

 

看别人代码的时候看到这样一个语句

  

 std::ios::sync_with_stdio(false);


google 了一下,发现它可以来消除iostream的输入输出缓存,可以节省很多时间.

有了那个语句之后,iostream 的效率和 stdin 就相差无几了。


更详细的参见:http://www.byvoid.com/blog/fast-readfile/


另外注意在程序中不要混合使用printf 和 cout ,会产生意想不到的结果...

printf("hello world");
cout
<<"this is a suprise";

can result in:

hellothis is a suprise world

 

posted on 2012-02-11 22:34  genslow  阅读(764)  评论(0编辑  收藏  举报