It's a matter of style and personal preference.
For header files, my personal preference is to make the header file stand on its own, but just barely. By "stand on its own" I mean that I should be able to #include
that header in some random source file and that source file will still compile.
#include "some_random_header_file.h"
int main () {}
The above should always compile. By "just barely", I mean that the header should be free of gratuitous #include
directives. If some #include
does not provide functionality used directly in a header file, I don't #include
that other header in the header file.
For source files, my personal preference is to #include
every header that provides functionality used in the source file. If the code a source file calls std::string::append
, that source file had better #include <string>
-- even if some other header has already included it.