stdio vs iostream [英] stdio vs iostream

查看:172
本文介绍了stdio vs iostream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在互联网上搜索这两个库之间的区别时,每个人都说< iostream> 是C ++和<$ c的标准I / O库我的教授说, cin>> cout<< cstdio> 不是好的函数,如果我们使用 cin>> 很多次我们的应用程序肯定会崩溃。他还说, stdio 提供的输入和输出速度比 iostream 快近3倍。但是,我更喜欢使用 iostream ,因为它更方便,我也不知道我的教授是否是对的。

When I search on the internet for the difference between these two libraries, everyone says that <iostream> is the standard I/O library of C++ and <cstdio> is for C. My professor says that cin>> and cout<< are not good functions and if we use cin>> many times our application will definitely crash. He also says that stdio provides nearly 3 times faster input and output than iostream. However, I prefer using iostream because it is more convenient, and also I don't know if my professor is right.

那么你建议我使用什么?

So what do you advise me to use?

推荐答案

使用 iostream 不应该让你的程序崩溃。它可能很慢,但这只是因为它试图与 stdio 进行互操作。该同步可以关闭 1 iostream 是惯用的C ++方式来获取输入,我建议在大多数情况下使用 stdio 使用C ++。

Using iostream should not make your program crash. It can be slow, but that's only because it's trying to interoperate with stdio. That synchronization can be turned off1. iostream is the idiomatic C++ way to get input, and I'd recommend its use over stdio functions in most cases when using C++.

1 使用 std :: ios :: sync_with_stdio(false);

这篇关于stdio vs iostream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆