0

This works in CLion:

#include <iostream>


int main()
{
    int min = INT_MAX;
    return 0;
}

But it doesn't on udacity where I'm learning C++: enter image description here

Why is there a need to add #include <climits> in some instances and not in others?

  • 10
    `` might include other `#include`, but you should not rely on that and include correct header to be portable. – Jarod42 Aug 09 '23 at 14:43
  • 2
    Do note that CLion isn't a compiler. It "works" for whatever C++ compiler you're actually using in the background (e.g. GCC, Clang, MSVC, ...) – Brian61354270 Aug 09 '23 at 14:44
  • @heapunderrun If you think this question is already answered elsewhere on this site, you should flag is as a duplicate. That way the target question gets directly linked to this question instead of forcing future visitors to search through the comments (which are transient and may be deleted) – Brian61354270 Aug 09 '23 at 14:47
  • @Brian61354270 For what it’s worth such comments *also* lead to these questions be linked on the right-hand “Linked” side bar. *Sometimes* this is more appropriate than closing a question as a duplicate. – Konrad Rudolph Aug 09 '23 at 14:49
  • @KonradRudolph Agreed, there's a place for both. Probably half of my comments on this site are "Related: " just for that purpose :) – Brian61354270 Aug 09 '23 at 14:56
  • The compiler is required to accept your program if it includes the correct headers, but not required to reject your program if it doesn't include them. This is an artefact of the ancient header mechanism, which is over half a century old by now. – molbdnilo Aug 09 '23 at 15:05
  • I'm not sure I understand what you mean @molbdnilo, can you re-explain? – FluidMechanics Potential Flows Aug 09 '23 at 16:15
  • Use your favorite search engine to look up "C++ transitive includes". – Jesper Juhl Aug 10 '23 at 07:25
  • So `iostream` sometimes include other heads, sometimes not? Are there different versions of `iostream` depending on where C++ was installed? – FluidMechanics Potential Flows Aug 10 '23 at 09:56

0 Answers0