included headers in the latest compilers

I always use to include string when declaring strings, however i noticed (after forgetting to include string) that my compiler ran it just fine without including it. I have Arch Linux with the latest G++ all the time, currently 4.8.2 20131219

So my questions are:
At what point did the compiler no longer require to include the header string, and what other headers might no longer need to be included as well with the latest compilers?
Last edited on
It does require the header.

Note that in some implementations of the std library, some headers happen to include others. This is something that cannot be relied on when switching compilers.

In your case <iostream> probably includes <string> or something.

Safest to include <string> anyways.
OK so it must be included in iostream library then as if i omit it i finally get the error. Although my questions still stands as which compiler does not include with iostream, soley because i checked MinGW on Windows and it is also included with the iostream library?
When I use Visual studio's compiler on windows, <string> is not included in <iostream>. However std::string is forward declared.

When I use g++ on linux, <string> is included in <iostream>
GCC's implementation of <iostream> has included the <string> header for as long as I can remember, but this is no guarantee. It might change in future versions.

It's best that you try to include all the headers you use but it's no big deal if you forget. It just means you, or someone else compiling your code, might have to add a lot of includes in the future if they happen to get errors because of it.
Last edited on
thanks for the info. Ill make sure to include the headers still to make it eeasier to transfer from one compiler to the other.
Topic archived. No new replies allowed.