Hello Ahmed, askers on this site are expected to do some research first on their own, show us what they found and why it did not suit their needs. A start, for example, could be to tell us is where you got the impression from that the kind of includes you mentioned are "bad". In the current form, expect your question to be closed as "unclear" or "primarily opinion based", since it contains hardly enough information to give you a sensible answer.
– Doc BrownJan 1 at 12:09

That’s not what guideline 9 says... it says not to include header files needed by the .cpp file if they are not needed by the .h file.
– James McLeodJan 1 at 12:36

@AhmedAdel: #9 says clearly, if string is required in A.h (because, for example, A.h contains a class definition with a string member), string should be included. So maybe you just misunderstood something?
– Doc BrownJan 1 at 13:00

1

in general, only include a header file in a file (which might be another header file) when the contents of the included header file are needed. Doing otherwise result in 'over' coupled code and too many recompiles needed when the original header file is updated.
– user3629249Jan 1 at 18:19

The rule is: Every header file should be capable of being compiled on its own. If you have a file myheader.h, then a source file with a single line #include "myheader.h" should compile.

If your header file doesn't compile without including another header file, then include that other header file. However, there are cases where the problem can be fixed just by using a forward declaration like "class otherclass;", if that is a case then it is very much preferable.

So DON'T include header files without a need, and avoid the need if you can.

Why not include other header files that are only used by the source file? Because your header file is supposed to be shared with other files. It is supposed to contain things you want to share. Why would you want to share internal details of your source files, like what headers it needs? You should share as little as possible.