gpt4 book ai didi

c++ - cstdio stdio.h 命名空间

转载 作者:IT老高 更新时间:2023-10-28 12:33:21 27 4
gpt4 key购买 nike

我从 cstdio 的 c++ 引用中看到这一行:

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

std::printf("hello world"); 

printf("hello world");

C++ header 是否将名称同时放在 std 和全局命名空间中

最佳答案

包括cstdio导入 std 中的符号名称命名空间和可能在全局命名空间中。
其中stdio.hstd 中导入全局命名空间中的符号名称和 可能命名空间。

这同样适用于所有 c 样式的标题。


引用:
C++11 标准

附录 D(规范性)兼容性特性 [depr] 规定:

D.6 C 标准库头文件

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> <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>

继续,

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 ]

关于c++ - cstdio stdio.h 命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10460250/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com