gpt4 book ai didi

c++ - 命名空间、 header 和对象的层次结构

转载 作者:行者123 更新时间:2023-11-28 01:51:11 25 4
gpt4 key购买 nike

据我了解,命名空间 std 包含所有 C++ 标准库,标准库之一是 iostream,它具有对象 cout 和 cin。

std namespace 
|
iostream
|
cout, cin

以上结构是否正确?还是有什么不同?

最佳答案

From what I understand, the namespace std contains all of C++ standard libraries, and one of the standard libraries is the iostream and it has the functions cout and cin.

不完全是。

  • 尽管几乎所有的标准库都在命名空间std 中,我们还有 std 之外的 C 组件当使用旧的标题形式( <stdio.h> 而不是 <cstdio> )和 assert 时没有作用域的宏。
  • std::cinstd::cout不是函数而是对象。
  • <iostream>只是一个 header 的名称,它包含 C++ ISO 标准正式命名为“输入/输出库”的部分(std::iostream 是一个很少使用的 typedef 用于 std::basic_iostream<char> 类)。
  • 图书馆的某些组件可以通过不同的方式拉入 #include秒。例如,std::initializer_list通过 <initializer_list> 可用或通过包含类似 <vector> .

无需赘述,头文件和作用域是 C++ 中的两个正交概念。换句话说,它们是平行存在的。它们之间没有有用的层次结构。

关于c++ - 命名空间、 header 和对象的层次结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42957970/

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