CDT
CDT

Reputation: 10641

C++ - include unistd.h: why not cunistd?

It's said that when including C header files in C++, the ".h" suffix should be removed and then add "c" at the beginning. For example, #include <cstdio> instead of #include <stdio.h>. But when I use sleep() in my code, #include <cunistd> does not work, but #include <unistd.h> works. Why not <cunistd>?

Upvotes: 85

Views: 55259

Answers (4)

babttz
babttz

Reputation: 466

unistd.h is not part of standard C. Standard C++ lib doesn't include it with the other c headers.

Upvotes: 6

Barath Ravikumar
Barath Ravikumar

Reputation: 5836

<unistd.h> , stands for unix standard header ,the name says it all.

Upvotes: 22

comocomocomocomo
comocomocomocomo

Reputation: 4942

Because unistd.h never was part of the C language. It is part of the Operating System.

Upvotes: 40

Carl Norum
Carl Norum

Reputation: 224944

Your algorithm is correct for most (all?) standard C headers, but unistd.h is not part of standard C so standard C++ in turn doesn't include it with the other c... headers.

Upvotes: 92

Related Questions