0

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++

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Narue
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.