cstdio stdio.h namespace(cstdio stdio.h 命名空间)
问题描述
我从 cstdio 的 c++ 参考中看到这一行:
I see this line from the c++ reference for cstdio:
库的每个元素都在 std 命名空间中定义.但我尝试了代码:
Every element of the library is defined within the std namespace.
but I tried the code:
std::printf("hello world");
printf("hello world");
C++ 标头是否将名称同时放在 std 和全局命名空间中?
推荐答案
包含 cstdio 会在 std 命名空间和 可能 中导入符号名称全局命名空间.
包含 stdio.h 会在全局命名空间中导入符号名称,可能会在 std 命名空间中导入符号名称.
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.
这同样适用于所有 c 样式的标题.
The same applies for all c-styled headers.
参考:
C++11 标准
Reference:
C++11 standard
附录 D(规范性)兼容性特性 [depr] 规定:
D.6 C 标准库头文件
1 为了与 C 标准库和 C Unicode TR 兼容,C++ 标准库提供了 25 个 C 标头,如表 151 所示.
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.
其中包括:
<代码><assert.h><float.h><数学.h><stddef.h><tgmath.h><代码><complex.h><inttypes.h><setjmp.h><stdio.h><time.h><代码><ctype.h><iso646.h><信号.h><stdint.h><uchar.h><代码><errno.h><limits.h><stdarg.h><stdlib.h><wchar.h><代码><fenv.h><locale.h><stdbool.h><字符串.h><wctype.h>
继续,
2 每个 C 头文件都有一个 name.h 形式的名称,其行为就像每个名称由相应的 cname 头文件放置在标准库命名空间中一样 放置在全局命名空间范围内. 未指定这些名称是否首先在命名空间 std 的命名空间范围(3.3.6)内声明或定义,然后通过显式注入到全局命名空间范围内使用声明 (7.3.3).
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 correspondingcname headeris 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 [ 示例:标题 确实在命名空间 std 中提供了它的声明和定义.它还可以在全局命名空间中提供这些名称.头文件 <stdlib.h> 确实在全局命名空间中提供了与 C 标准中相同的声明和定义.它还可以在命名空间 std 中提供这些名称.——结束示例]
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 命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:cstdio stdio.h 命名空间
基础教程推荐
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- c++ STL设置差异 2022-01-01
