In C++, am I paying for what I am not eating?

后端 未结 13 2043
既然无缘
既然无缘 2020-12-12 12:39

Let\'s consider the following hello world examples in C and C++:

main.c

#include 

int main()
{
    printf(\"Hello world\\n\");
    r         


        
13条回答
  •  没有蜡笔的小新
    2020-12-12 13:03

    So, in this case, what am I paying for?

    std::cout is more powerful and complicated than printf. It supports things like locales, stateful formatting flags, and more.

    If you don't need those, use std::printf or std::puts - they're available in .


    It is famous that in C++ you pay for what you eat.

    I also want to make it clear that C++ != The C++ Standard Library. The Standard Library is supposed to be general-purpose and "fast enough", but it will often be slower than a specialized implementation of what you need.

    On the other hand, the C++ language strives to make it possible to write code without paying unnecessary extra hidden costs (e.g. opt-in virtual, no garbage collection).

提交回复
热议问题