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