Mark
Mark

Reputation: 8678

Getting fatal error when including <stdlib>

I got a fatal error that the file or directory <stdlib> is not found on ubuntu 11.xx when I typed #include <stdlib>.

Is <stdlib> deprecated/removed, or is there something wrong with my GCC installation?

Upvotes: 6

Views: 15138

Answers (2)

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385098

Presumably you are attempting to include the C standard library header stdlib.h.

Thing is, in C++, the old C headers x.h are deprecated; you should not use them. Fortunately, C++ allows you to use C++ versions of them:

#include <cstdlib>

It's pretty much the same thing, but wrapped into the std:: namespace ... and not deprecated.

Anyway, you got your error because there's certainly no standard header named just stdlib.

Upvotes: 0

Andr&#233; Puel
Andr&#233; Puel

Reputation: 9179

In C++ code, include 'cstdlib' instead.

#include <cstdlib>

If you are using C, include 'stdlib.h'

#include <stdlib.h>

In c++ code, always prefer the cXXX include instead of XXX.h

Upvotes: 18

Related Questions