Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 662
vladutcornel Avatar asked Sep 29 '11 11:09

vladutcornel


3 Answers

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 ]

like image 127
Lightness Races in Orbit Avatar answered Oct 28 '22 07:10

Lightness Races in Orbit


It's not true, because C++ main goal is backward compatibility with C. The only difference is that for

#include <cstdio>

all functions are in std namespace

like image 8
GreenScape Avatar answered Oct 28 '22 06:10

GreenScape


The C standard headers are included in the C++ standard library for compatibility.

The difference is that identifiers in corresponding C++ headers must (also) be in std namespace, whereas identifiers in C headers must (also) be available in global namespace.

In addition, the <c...> headers add overloads for functions like abs, pow etc.

Also, C++ headers replace some C classification/comparison macros with overloaded functions.

like image 3
visitor Avatar answered Oct 28 '22 07:10

visitor