ios::sync_with_stdio(false)提高C++读写速度

 

C++为了兼容C,默认使iostream与stdio关联,使cin与scanf、cout和printf保持同步,保证混用过程中文件指针不混乱。
此方式会造成性能损失,导致使用cin/cout效率远远低于使用scanf/printf。若保证程序只是用一套指令,可取消同步:

std::ios::sync_with_stdio(false);

取消后使用cin/cout速度有明显提升,但注意不要混用iostream与stdio

std::cin.tie(0);

C++98:In terms of static initialization order, cin is guaranteed to be properly constructed and initialized no later than the first time an object of type ios_base::Init is constructed.

C++11:In terms of static initialization order, cin is guaranteed to be properly constructed and initialized no later than the first time an object of type

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值