c语言cin和cout_不要在c中使用cin和cout

c语言cin和cout

This is the case for competitive programming. In competitive, the cin and cout command tends to take more execution time than its counterparts scanf and printf.

竞争性编程就是这种情况。 在竞争中,cin和cout命令往往比其对应的scanf和printf花费更多的执行时间。

The scanf and printf command may usually be used in C language but it tends to perform better and faster than other commands. But the problem which arises with using print is that we have to remember each and keyword for each data type. Such as :

scanf和printf命令通常可以用C语言使用,但是它的性能往往比其他命令更好和更快。 但是使用print出现的问题是,我们必须记住每种数据类型的参数和关键字。 如 :

int x = 5;
printf("%d",x);

As in this, for int data type, it ‘d’ for float it is ‘f’ along with the number of decimal places we want to include in it.

像这样,对于int数据类型,对于浮点数,其为'd';对于我们要包含在其中的小数位数,它为'f'。

printf("%0.2f",x);

This command will print only up to 2 decimal places for the floating type number.

此命令最多只将浮点型数字打印2个小数位。

Overall (maybe I just went a little too ahead with the commands), As of writing and remembering these new syntaxes may take up more of our time and as time is very precious in any competition. So the solution to this problem is to use the ios base command:

总体而言(也许我只是在命令方面有点过头),在编写和记住这些新语法时可能会占用我们更多的时间,并且时间在任何竞争中都非常宝贵。 因此,解决此问题的方法是使用ios base命令:

ios_base::sync_with_stdio(false);cin.tie(NULL);

This may look a bit over the top or a bit strange. But this command just has a simple functionality such that it just converts any cin or cout command to scanf and printf respectively in the background. The benefits of using this are:

这可能看起来有点过顶或有些奇怪。 但是此命令仅具有简单的功能,因此仅在后台将任何cin或cout命令分别转换为scanf和printf。 使用它的好处是:

  • We can keep using our old cin and cout commands

    我们可以继续使用旧的cin和cout命令
  • We can enjoy the execution time of scanf and printf without actually even either implementing or remembering the syntax.

    我们可以享受到scanf和printf的执行时间,而实际上并没有实现或记住语法。

翻译自: https://medium.com/@rajataggarwal2603/dont-use-cin-and-cout-in-c-89e9c70701f5

c语言cin和cout

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值