should I include a header that is already included via other headers?

Viewed 4917

I had only just noticed my programs using the string class were compiling without including the <string> header. It turns out that <iostream> includes <ios_base> which in turn includes <string>.

Is this bad practice and should I explicitly include <string>? Even if it's just a case of clarity?

Is it safe to assume this applies to more than just the <string> header? Perhaps this is implementation specific and or does the standard state the <string> header be included via <ios_base> and <iostream>? Ensuring that any respected and widely used implementation will always include <string> providing the the call to <iostream> exists.

3 Answers
Related