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关联(绑定时cin之前会将cout输出缓冲区的数据刷新到输出文件),可以避免当cout缓冲区的数据没有刷新到文件中时使用了cin,这样就可能发生数据不一致,通过绑定可以在输入前将cout数据输出的文件中。默认时绑定的。

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)的联系,可以提升输入输出速率,但解除之后不能混合使用。

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐