I have a c++ program that uses the rand function and the srand function.
It worked fine when I compiled it on my windows machine, but I got errors when trying to compile it on ubuntu linux.

After I included cstdlib the program worked fine on the linux too.


1.
Is it true that IDE/compilers will automatically include some things?
If yes, is there a compiler for windows that won't?

2.
Is every library that end with .h for C, not C++? (Like stdlib.h)
for example Wikipedia said stdlib.h is used for C and cstdlib for c++

Is it true that IDE/compilers will automatically include some things?

It's possible, yes.

If yes, is there a compiler for windows that won't?

The proper solution is to know exactly what you're using and explicitly include the correct header. If you're expecting the compiler to catch every error, you'll be greatly disappointed.

Is every library that end with .h for C, not C++? (Like stdlib.h)

No. When it comes to the standard headers, the <c*> headers simply wrap the <*.h> headers in the std namespace. Both are perfectly legal to use in C++. The <*.h> headers are technically deprecated, but for all practical purposes they're not going anywhere.

When it comes to headers you create, *.h and *.hpp are two common conventions, but they're not required at all.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.