Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cstdio stdio.h namespace

Tags:

c++

header

I see this line from the c++ reference for cstdio:

Every element of the library is defined within the std namespace. but I tried the code:

std::printf("hello world");   printf("hello world"); 

is it true that C++ headers puts the names in both the std and the global namespace?

like image 618
danny Avatar asked May 05 '12 08:05

danny


People also ask

What is the difference between cstdio and Stdio H?

Including cstdio imports the symbol names in std namespace and possibly in Global namespace. Including stdio. h imports the symbol names in Global namespace and possibly in std namespace. The same applies for all c-styled headers.

What is the use of cstdio in C++?

The cstdio header file contains definitions for C++ for performing input and output. Include the standard header into a C++ program to effectively include the standard header <stdio. h> within the std namespace.

Is Stdio H available in C++?

YES WE CAN USE BECAUSE INPUT AND OUTPUT OPERATIONS CAN ALSO BE PERFORMED IN C++ ALSO. BECAUSE C/C++ USES WHAT ARE CALLED STREAMS TO OPERATE WITH PHYSICAL DEVICES SUCH AS KEYWORDS,PRINTERS TERMINALS OR ANY OTHER TYPE OF FILES SUPPORTED BY THE SYSTEM.

What is the Stdio H header file?

stdio. h is a header file which has the necessary information to include the input/output related functions in our program. Example printf, scanf etc. If we want to use printf or scanf function in our program, we should include the stdio. h header file in our source code.


1 Answers

Including cstdio imports the symbol names in std namespace and possibly in Global namespace.
Including stdio.h imports the symbol names in Global namespace and possibly in std namespace.

The same applies for all c-styled headers.


Reference:
C++11 standard

Annex D (normative) Compatibility features [depr] states:

D.6 C standard library headers

1 For compatibility with the C standard library and the C Unicode TR, the C++ standard library provides the 25 C headers, as shown in Table 151.

Which include:

<assert.h> <float.h> <math.h> <stddef.h> <tgmath.h> <complex.h> <inttypes.h> <setjmp.h> <stdio.h> <time.h> <ctype.h> <iso646.h> <signal.h> <stdint.h> <uchar.h> <errno.h> <limits.h> <stdarg.h> <stdlib.h> <wchar.h> <fenv.h> <locale.h> <stdbool.h> <string.h> <wctype.h>

Further on,

2 Every C header, each of which has a name of the form name.h, behaves as if each name placed in the standard library namespace by the corresponding cname header is placed within the global namespace scope. It is unspecified whether these names are first declared or defined within namespace scope (3.3.6) of the namespace std and are then injected into the global namespace scope by explicit using-declarations (7.3.3).

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 176
Alok Save Avatar answered Sep 25 '22 13:09

Alok Save