What's the main difference between stdlib.h and cstdlib in C++?
I'm using EXIT_FAILURE macro, so I need to include stdlib.h or cstdlib. But I don't know what the difference is. Should I use cXXX style header file rather than XXX.h?
Thank you.开发者_运维知识库
<cstdlib>
is just <stdlib.h>
wrapped in the std
namespace. You should use <cstdlib>
in order to be keep your global namespace clean.
As EXIT_FAILURE is a macro, it makes no difference which you include. The cstdlib
version will put the names of all the functions into the std
namespace, so you can say things like:
std::exit(0);
but as macros don't respect namespaces, you can't say:
std::EXIT_FAILURE
精彩评论