Search code examples
c++stdiostandard-library

stdio.h not standard in C++?


I know most compilers allow both:

#include <stdio.h>

and

#include <cstdio>

But someone argued that <stdio.h> is not actually C++ standard. Is that true?


Solution

  • stdio.h is standard, but deprecated. Always prefer cstdio in C++.

    [n3290: C.3.1/1]: For compatibility with the Standard C library, the C++ standard library provides the 18 C headers (D.5), but their use is deprecated in C++.

    [n3290: D.5/3]: [ Example: The header <cstdlib> assuredly provides its declarations and definitions within the namespace std. It may also provide these names within the global namespace. The header <stdlib.h> assuredly provides the same declarations and definitions within the global namespace, much as in the C Standard. It may also provide these names within the namespace std. —end example ]