在 C++ 程序中使用 C (<cstdio>) 风格代码有什么好的理由吗?

问题描述 投票:0回答:1

我见过一些程序将 C 和 C++ 代码混合在一个 C++ 程序中(甚至在编码面试中)。

据我所知,所有类型的问题都可以单独使用 C++ 来解决和开发,所以我想知道是否存在需要通过

<cstdio>
库将 C 代码引入到程序中的情况?

c++
1个回答
0
投票

C++中的输出或输入等计算部分比C中的输出或输入具有更大的内存容量。 因此,当尝试使用减少计算量和减少内存容量的优化方法时,会使用诸如此类的库。

C++:cout<< val << endl; C: printf("%d", val); "cout" is an object class variable, and when output, it consumes as much memory as the object along with the class call. However, "printf" consumes only the capacity of the val variable.

© www.soinside.com 2019 - 2024. All rights reserved.