What C ++ heading do the other headings include?

I am confused which standard library includes one another. I heard that iostream includes ostream or something like that. Unfortunately, I could not find a review. That is why I am asking now.

My program uses the following libraries: string, fstream , iostream , streambuf , streambuf . Since they provide related functionality, I wonder if any of them have one more of them. In this case, I could get rid of excess inclusions.

Is there a review indicating which standard library includes which ones? or Which of the library users in my program is redundant?

+4
source share
5 answers

C ++ makes no guarantees whatsoever for any kind of recursive inclusion. You are responsible for including all the headings you need. Similarly, this does not guarantee that any particular standard library header will be omitted. (For example, your implementation can legally always include all the standard library headers!) That's why-and-because everything is in the std .

(I believe there is a special provision for C library headers - I think you won’t get names in the global namespace unless you explicitly include these headers.)

Some headings have special requirements; for example, C ++ 11 (but not earlier) requires that <iostream> include both <ostream> and <istream> . But this is just one specific case.

+7
source

You cannot rely on any headings to be included in other headings. It is best to include everything you need. Thus, if you change the compiler, you can not break the compilation if the new compiler does not have the same header structure as the structure.

+2
source

This may help: http://www.cplusplus.com/reference/iostream/iostream/ iostream inherits from ostream and istream.

+1
source

My rule: #include what you use. If you use std::string , you need #include <string> . If you use std::cout , you need #include <iostream> . If you use a file stream, #include <fstream> . And so on.

So that you can get std::string for "free" from some of the other system headers that you include, it doesn't matter. Do not depend on those who are behind the curtains.

+1
source

If you are worried that you have a backup, they are processed using macros, for example

#ifndef MACRO_NAME #define MACRO_NAME

#endif

So you don’t need to worry about a few inclusions, I think.

+1
source

Source: https://habr.com/ru/post/1438422/


All Articles