很多人会说cin的速度比 scanf 慢很多, 其实不然.
cin慢的原因主要在于默认 cin 与 stdin 总是保持同步, 这一步是消耗时间大户.
只需要加上std::ios::sync_with_stdio(false)来关闭同步就好了, 速度甚至要优于 scanf.
但极可能与其他c++自带库函数相冲突,谨慎食用
代码具体实现


#include<bits/stdc++.h>
using namesapce std;
int main()
{
  int a,b;
  std::ios::sync_with_stdio(false);
  cin>>a>>b;
  cout<<a+b;
}

WzzOrz

相关文章:

  • 2022-12-23
  • 2021-06-05
  • 2018-10-10
  • 2021-12-01
  • 2022-12-23
  • 2021-05-18
  • 2021-12-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2022-02-01
  • 2021-11-20
相关资源
相似解决方案