C++ code compiles without include

后端 未结 2 1607
小鲜肉
小鲜肉 2020-12-11 19:52

Why I don\'t need to include cstdlib and how do I disable this? I\'m using Code::Blocks with GCC compiler on Windows 7.

#include 

using std:         


        
2条回答
  •  暖寄归人
    2020-12-11 20:31

    You don't need to include because it (or the part of it containing system()) was included by . It is unspecified whether or which other (standard) headers are included by standard headers. You cannot disable this behavior but should be aware of it to avoid portability problems between different standard library implementations.

    You should not depend on this behavior and include yourself. You should also use std::system instead of the global system. Functions from headers are only guaranteed to be in the std namespace (the global ones, on the other hand, in the <*.h> headers).

提交回复
热议问题