简体   繁体   English

iostream是头还是库

[英]Is iostream a header or a library

I have just started learning cpp and one thing that is really confusing me is #include <iostream> or #include<vector> .我刚刚开始学习 cpp,真正让我困惑的一件事是#include <iostream>#include<vector> Some people say that we are including iostream library and some say that #include is used for including header files.有人说我们正在包含 iostream 库,有人说#include用于包含头文件。 But iostream and vector don't have .h extension so how can they be header files?但是iostreamvector没有.h扩展名,那么它们怎么可能是头文件呢? Also, can we include a library by using #include ?另外,我们可以使用#include来包含一个库吗? This also makes me think about difference between iostream.h and iostream .这也让我想到了iostream.hiostream之间的区别。 Which one is header file?哪个是头文件? Which one is library?哪个是图书馆? If we are only including header files then why don't we write #include<vector.h> ?如果我们只包含头文件,那我们为什么不写#include<vector.h>呢?

What does the standard cpp library contain?标准cpp库包含什么? Smaller libraries like containers library, utilities library?容器库、实用程序库等较小的库?

I tried looking on cppreference but couldn't understand我试着查看 cppreference 但无法理解

iostream and others are header files. iostream等都是头文件。

Usually headers have .h or .hpp extension, but it's merely a convention.通常标头具有.h.hpp扩展名,但这只是一种约定。 The C++ standard library uses a different convention, which is to have no extension. C++ 标准库使用不同的约定,即没有扩展名。


What counts as a library is moot.什么算作图书馆是没有实际意义的。 A "library" can mean either: “图书馆”可以指:

  1. A single .a , .so , .lib , or .dll file (or something else, depending on your platform).单个.a.so.lib.dll文件(或其他文件,具体取决于您的平台)。
  2. A collection of predefined entities for a programmer to use.供程序员使用的预定义实体的集合。

The individual standard headers are definitely not (1).个别标准标头绝对不是(1)。 The whole standard library is (2), and is usually split into several (1)s.整个标准库是(2),通常分成几个(1)。

Whether each individual standard header counts as (2) is moot, I wouldn't call them that.每个单独的标准标头是否算作 (2) 都没有实际意义,我不会那样称呼它们。

The C++ standard splits the standard library into several header groups , and calls each a "library" (2). C++ 标准将标准库拆分为多个头文件组,并将每个头文件组称为“库”(2)。 Cppreference does the same. Cppreference做同样的事情。

Put it this way: iostream and other #include items are really header files containing libraries of built-in functions and other things in the C++ language.这么说吧:iostream 和其他#include 项实际上是包含内置函数库和 C++ 语言中其他内容的头文件。 specifically helps you with input and output through the terminal using cin, cout, and more.专门帮助您使用 cin、cout 等通过终端进行输入和输出。 Also, here is a tip: if you want to avoid the tedious need to add each header file so you can use a variety of functions and other items, just #include <bits/stdc++.h>, which is really just a header that includes every other header and their libraries;另外,这里有一个提示:如果你想避免添加每个头文件的繁琐,以便你可以使用各种函数和其他项目,只需#include <bits/stdc++.h>,它实际上只是一个头文件包括所有其他标题及其库; It should make your life easier.它应该让你的生活更轻松。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM