-1

If I have ,let's say, a header file that contains <iostream> in it ,my main.cpp also contains <iostream>, this repetition could bring problems? If yes , how can I avoid this?

Robert
  • 71
  • 8
  • 5
    No, there aren't any problems due to correct [header guards](https://stackoverflow.com/questions/4767068/header-guards-in-c-and-c). If you have a concrete case, where you're facing problems give us a [mcve] please. – πάντα ῥεῖ Dec 07 '20 at 21:43

1 Answers1

1

No, there are no problems here.

[using.headers/2]: A translation unit may include library headers in any order ([lex.separate]). Each may be included more than once, with no effect different from being included exactly once, except that the effect of including either <cassert> or <assert.h> depends each time on the lexically current definition of NDEBUG.174 A translation unit may include library headers in any order ([lex.separate]). Each may be included more than once, with no effect different from being included exactly once, except that the effect of including either <cassert> or <assert.h> depends each time on the lexically current definition of NDEBUG.174

Typically this is achieved using header guards, or a #pragma once.

I'm ignoring the caveat about NDEBUG, because you should not be setting or unsetting that using #define or #undef, but instead setting it (or not setting it) en masse across your build.

Asteroids With Wings
  • 17,071
  • 2
  • 21
  • 35