Difference between "<iostream>" or "<stdlib. h> <stdio. h>" in #include

Asked

Viewed 5,346 times

3

I am learning to code in c++, and I would like to know the difference in programming with the library

#include <iostream>

or libraries

#include <stdlib.h>
#include <stdio.h>

One I would use things like std::cout e std::cin and another I would use printf e scanf.

I need to know how to program with both or I can follow in one, which in case I was learning from the std::cout? They have a difference in performance or something?

1 answer

8


One is the I/O of the standard C library, another is the I/O of the Standard Template Library (STL) for C++. There should be no substantial difference in performance between them.

As a professional in the field, it’s good to know both of them, because V. will find both in third-party code.

In C++ you have the choice of a OR other, I suggest not to mix because I/O is bufferized (temporarily stored in memory), then file recording or console display (stdout/Cout) can happen in a different order than you expected.

I personally prefer the C library because of printf() masks that I know best and are employed in many languages other than C, but don’t take this as a recommendation. Use one and the other and see which one you like best. A lot of people would say that if you program in C++ you should avoid the standard C library, preferring the STL.

  • Thanks for the answer, I will get a knowledge to understand the standard C library and I will continue to use the (STL), because I learned it initially and I feel more comfortable with it.

  • 3

    I really like this answer. Tried to avoid the war of opinions between style 'c' and style 'c+'. Both styles have good and bad points.

  • @Kylea was worth it :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.