Which header version for C++?

After learning C++ for a few days now I am abit confused about which header files I should include in certain cases. I have noticed that there are different "versions" of some libraries. There are for example "<cstdlib" and "stdlib", "cstring" and "string".

Which one should you choose for cross platform c++ projects? Which one is the best? I guess that the "c"-ones are later versions for c++ and not for just c.
So should I always go for the "c..."-headers? Are they the best?
So should I always go for the "c..."-headers?

When writing C++ specific code, yes.

But you do need to include (e.g.) <stdlib.h> in a header intended for use by both C++ and C code.

And be careful about <string> (which defines the std::string class) versus <string.h> (the C library string routines), and <cstring> the C++ wrapper for <string.h>

You use <cstdlib>, <cstring>, ... rather than <stdlib.h>, <string.h>, ... so the C library functions are declared within the std namespace.

Last edited on
Topic archived. No new replies allowed.