I am confused of which standard library include which other once. I heard that iostream
includes ostream
or something like that. Unfortunately I couldn't find an overview. That's why I ask now.
My program uses the following libraries: string, fstream
, iostream
, sstream
, streambuf
. Because they provide related functionality I wonder if any of these includes another of them already. In this case I could get rid of the redundant includes.
Is there a overview out there indicating which standard library includes which? or Which of the libraries user by my program are redundant?
C++ provides no guarantees in general for any sort of recursive inclusion. It is your responsibility to always include all headers that you need. Similarly, it does not guarantee that any particular standard library header is not included. (For example, your implementation could legally always include all standard library headers!) That's why-and-because everything is in the std
namespace.
(I believe there's a special provision for the C library headers - I think you won't get names in the global namespace unless you explicitly include those headers.)
Some headers do have specific requirements; for example, in C++11 (but not before) it is required that <iostream>
include both <ostream>
and <istream>
. But that's just one specific case.
You can't rely on any headers being included by any other headers. It's best to explicitly include everything you need. That way, if you change the compiler, you can be sure not to break compilation, in case the new compiler doesn't have the same header include structure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With