cin.tie(0)和ios::sync_with_stdio(false)
cin is tied to the standard output stream cout (see ios::tie), which indicates that cout’s buffer is flushed (see ostream::flush) before each i/o operation performed on cin.
cin.tie(0)操作解除cin 和 cout關聯(lián)(綁定時cin之前會將cout輸出緩沖區(qū)的數(shù)據(jù)刷新到輸出文件),可以避免當cout緩沖區(qū)的數(shù)據(jù)沒有刷新到文件中時使用了cin,這樣就可能發(fā)生數(shù)據(jù)不一致,通過綁定可以在輸入前將cout數(shù)據(jù)輸出的文件中。默認時綁定的。
If the streams are synchronized, a program can mix iostream operations with stdio operations, and their observable effects are guaranteed to follow the same order as used in the thread.
解除與c輸入輸出stdio(scanf、printf)的聯(lián)系,可以提升輸入輸出速率,但解除之后不能混合使用。
總結(jié)
以上是生活随笔為你收集整理的cin.tie(0)和ios::sync_with_stdio(false)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: KS检验、t检验、f检验、Grubbs检
- 下一篇: C++的tie()函数