cstdio stdio.h命名空间 [英] cstdio stdio.h namespace

查看:342
本文介绍了cstdio stdio.h命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 cstdio 的c ++参考中看到这一行:



库的每个元素在 std命名空间
中定义,但我尝试了以下代码:

  std :: printf(hello world); 

printf(hello world);

这是真的 C ++标头将名称放在std和全局命名空间

解决方案

包含 cstdio std 命名空间中导入符号名称,并在全局命名空间中导入

包括 stdio。 h 在全局命名空间中导入符号名称,并在 std 命名空间中导入可能



这同样适用于所有c风格的标头。






参考:

C ++ 11标准



附件D(规范)兼容性功能[depr]

1为了与C标准库和C Unicode TR兼容,C ++标准库提供了25个C头,如表151所示。


其中包括:


< assert.h> < float.h> < math.h> < stdef.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>


更进一步,


2 每个C头文件的名称都是 name.h 通过相应的 cname头放置在标准库命名空间中的代码放置在全局命名空间范围内。未指定这些名称是否首先在命名空间范围内声明或定义(3.3.6)的命名空间std,然后通过显式使用声明(7.3.3)注入全局命名空间范围。



3 [示例: < cstdlib> 在命名空间std中可靠地提供其声明和定义。它还可以在全局命名空间中提供这些名称。标题< stdlib.h> 可以在全局命名空间中提供相同的声明和定义,与C标准一样。它还可以在命名空间std中提供这些名称。 -end example]



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?

解决方案

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 ]

这篇关于cstdio stdio.h命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆